请问asp。net中,sqldatareader的用法?
SqlConnectionconn=newSqlConnection();conn.ConnectionString=ConfigurationManager.Conne...
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["ReadersConnectionString"].ToString();
conn.Open();
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandText = strsql;
//comm.Parameters["@Author"].Value = Convert.ToString(txtSelectedName.Text);
SqlDataReader sdr = comm.ExecuteReader();
GridView1.DataSource = sdr;
GridView1.DataBind();
sdr.Close();
conn.Close();
像以上代码SqlDataReader sdr = comm.ExecuteReader();
并没有循环执行,sqldatareader中应该保存的只是一行,但是为啥gridview能显示出很多行? 展开
conn.ConnectionString = ConfigurationManager.ConnectionStrings["ReadersConnectionString"].ToString();
conn.Open();
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandText = strsql;
//comm.Parameters["@Author"].Value = Convert.ToString(txtSelectedName.Text);
SqlDataReader sdr = comm.ExecuteReader();
GridView1.DataSource = sdr;
GridView1.DataBind();
sdr.Close();
conn.Close();
像以上代码SqlDataReader sdr = comm.ExecuteReader();
并没有循环执行,sqldatareader中应该保存的只是一行,但是为啥gridview能显示出很多行? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询