朋友们,当我在 asp.net 中编写这些代码时,我收到如下错误:
已经有一个打开的 DataReader 与此命令关联,必须先关闭
请帮帮我
SqlConnection con = obj.getcon();
con.Open();
SqlCommand cmd = new SqlCommand("select student_id from student_details", con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
String ss=dr[0].ToString();
if (val == ss)
{
SqlCommand cmd1 = new SqlCommand("insert student_vs_testsession_details(student_id,testsession_id,testsession_status) values('" + val + "','" + Test + "','')", con);
int val1 = cmd1.ExecuteNonQuery();
}
else
{
string message = "<script language=JavaScript> alert('StudentID does not exists!'); </script>";
if (!Page.IsStartupScriptRegistered("clientScript"))
{
Page.RegisterStartupScript("clientScript", message);
}
}
}
dr.Close();
// con.Close();
}