我的程序里面Sqlcommand cmd = new Sqlcommand("select * from table1", conn);myGridView.DataSource = cmd.ExecuteReader();myGridView.DataBind();....然后我下面的程序再执行sqlcommand命令时,它就会报错:有打开的与此命令相关联的 DataReader,必须首先将它关闭。请问我要如何关闭 DataRead 啊,我上面的程序并没有产生 SqlDataReader 的实例啊!谢谢!
SqlConnection con = "";//数据库连接语句
string sSQL = "select * from 表";
SqlDataAdapter adr = new SqlDataAdapter(sSQL, con);
DataSet Ds=new DataSet();
adr.Fill(Ds);
在Sqlcommand cmd = new Sqlcommand("select * from table1", conn);前
.......
dr.close()
conn.Open;
在Sqlcommand cmd = new Sqlcommand("select * from table1", conn);
SqlDataAdapter da =new SqlDataAdapter("select * from table1", conn);
DataSet ds = new DataSet();
da.Fill(ds, "mytable");
myGridView.DataSource = ds.Tables["mytable"].DefaultView;
myGridView.DataBind();
cmd.ExecuteReader();返回的是DataReader类型啊~
cmd执行了操作的~
cmd.dispose()下就可以了~
你执行完成了,就要把conn关闭,不然会超过连接池最大连接限制。