需要循环得到用户名
while(reader.Read())
{
string WBN=reader["WasteBookNo"].ToString();
然后执行存储过程和其他代码,但是执行存储过程myCommand.ExecuteNonQuery();的时候提示出错:已有打开的与此连接相关联的 DataReader,必须首先将它关闭。
}
我该怎么解决,能不能先把用户名读到datatable里,然后循环查询datatable 怎么查呢?
while(reader.Read())
{
string WBN=reader["WasteBookNo"].ToString();
然后执行存储过程和其他代码,但是执行存储过程myCommand.ExecuteNonQuery();的时候提示出错:已有打开的与此连接相关联的 DataReader,必须首先将它关闭。
}
我该怎么解决,能不能先把用户名读到datatable里,然后循环查询datatable 怎么查呢?
SqlDataAdater da = new SqlDataAdapter("",myConn);
DataTable dt = new DataTable();
da.Fill(dt);
for(int i = 0;i< dt.Rows.Count;i++)
{
string WBN = dt.Rows[i]["WasteBookNo"].ToString();
//__-----------
}
用using ()
{
}
也不行
改为
while(reader.Read())
{
string WBN=reader["WasteBookNo"].ToString();
}
reader.close();
就改DataReader为DataSet
int count=myDataSet.Tables["--"].Rows.Count;
for(int i=0;i<count;i++)
{
string WBN=myDataSet.Tables.Rows[i]["WasteBookNo"].ToString();/////myCommand.ExecuteNonQuery();}