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();
}
データ リーダーが 1 つの「select ステートメント」を取得し、それを読み取って Gridview にバインドする理由について混乱していますが、次の一連の「select ステートメント」を使用することになると、データ リーダーは何もしません。 . dr.Read()
になりfalse
ます。
なぜこれが起こるのか教えてください。