protected void btnFetch_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(Helper.ConStr);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "select * from emptable";
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
gv1.DataSource = dr;
gv1.DataBind();
dr.NextResult();
**while (dr.Read())**//It is returning the value as false!
{
SqlCommand cmd1 = new SqlCommand();
cmd1.CommandText = "select * from table1";
Response.Write(dr[0]);
Response.Write(dr[1]);
}
con.Close();
}
我很困惑为什么,数据读取器选择一个“选择语句”,读取它并将其绑定到 Gridview 但是当涉及到使用下一组“选择语句”时,数据读取器不做任何事情. dr.Read()
变成false
.
请向我解释为什么会发生这种情况?