while (dr.Read())
cmd.CommandText = "select top 100 * from lwmain where bj='0' order by id";
SqlDataReader dr21 = cmd.ExecuteReader();
while (dr21.Read())
{
dd = dr21["dd"].ToString();
xjsj = dr21["xjsj"].ToString();
dr21.Close();
dr21.Dispose();
cmd.CommandText = "select * from lwjhkh where kssj<='" + xjsj + "' and jssj>='" + xjsj + "' and dd='" + dd + "' and khzt='未到' and jhms='未到'";
SqlDataReader dr22 = cmd.ExecuteReader();
.......................
}
这么写的话报错,在while循环一次执行第2次的时候就会报“阅读器关闭时尝试调用Read无效” ,请问高手这个问题怎么解决,怎样可以循环执行
------解决方案--------------------为什么要在循环里关闭dr21?
dr21.Close();
dr21.Dispose();
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/
------解决方案--------------------改成用DataSet
------解决方案--------------------建立两个SQLCONNECT,分别对应两个SqlDataReader,分别关闭就行了。
------解决方案--------------------
可以写成函数方式,类似这样:
private void button4_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand(); ;
cmd.CommandText = "select top 100 * from lwmain where bj='0' order by id";
SqlDataReader dr21 = cmd.ExecuteReader();
while (dr21.Read())
{
string dd = dr21["dd"].ToString();
string x