1
1楼 shilft 2007-03-19 15:03:08 想用gridview分页显示数据库中的数据,程序调试出现一个问题,不知道怎么解决: 类:database.cs public class database { public database() { // // TODO: 在此处添加构造函数逻辑 // } public DataTable Select() { //这是我之前写的,连接数据库都没有问题,现在却出错了,我注释掉了 //SqlConnection Conn = new SqlConnection(ConfigurationManager.ConnectionStrings[ "ConnString "].ToString()); //SqlCommand Cmd = new SqlCommand(); //Cmd.CommandText = "dbo.Select_Cum "; //Cmd.CommandType = CommandType.StoredProcedure; //Cmd.Connection = Conn; //DataTable dt = new DataTable( "Customer "); //SqlDataAdapter da = new SqlDataAdapter(Cmd); //if (Conn.State.ToString() == "closed ") //{ // Conn.Open(); //} //da.Fill(dt); //return dt; //if (Conn.State.ToString() == "open ") //{ // Conn.Close(); //} //Cmd.Dispose(); //这是以前一个程序中的,也是调试好好的 SqlConnection Conn = new SqlConnection(ConfigurationManager.ConnectionStrings[ "ConnString "].ToString()); string sql = "Select Cum_No,Cum_Name from Customer "; SqlCommand cmd = new SqlCommand(sql, Conn); DataTable dt = new DataTable( "Customer "); SqlDataAdapter da = new SqlDataAdapter(cmd); cmd.Connection = Conn; Conn.Open();//程序运行到这里出错 da.Fill(dt); return dt; Conn.Close(); cmd.Dispose(); da.Dispose(); } } .aspx.cs protected void Page_Load(object sender, EventArgs e) { database db = new database(); GridView1.DataSource = db.Select(); GridView1.DataBind(); Label1_total.Text = "总共 " + GridView1.PageCount.ToString() + "页 "; Label2_currentpage.Text = "第 " + (GridView1.PageIndex + 1).ToString() + "页 "; } 错误是:超时时间已到。超时时间已到,但是尚未从池中获取连接。出现这种情况可能是因为所有池连接均在使用,并且达到了最大池大小。 连接池只是了解,这个问题不知道从何解决,我用datagrid就可以正确显示数据,在以前写的一段代码中也可以用gridview显示,这次不知道怎么就是出错? 2楼 boytomato 2007-03-19 15:27:30 估计不是这的问题,是你其他地方调用后没关闭还是其他的,,, 用查询分析器看一下。。。。 3楼 messm 2007-03-19 15:30:10 你连接字符串多对了? 4楼 biao1 2007-03-19 15:43:34 少了这个吧
SqlConnection myConnection = new SqlConnection(sqlconn); myConnection.Open();
搜索墙@2009 www.pkwall.com all rights reserved QQ:276471788 [京ICP备09111534号]
声明:本站部分数据来源于网络,仅供参考,如有版权问题,请联系我们,我们将及时删除!转载本站请注明来源
| |||||