关于dr.read()的问题 很急!
private void Button1_Click(object sender, System.EventArgs e)
{
SqlConnection MyConnection=new SqlConnection("Data Source=(local);database=学生;uid=tq;pwd=1") ;
SqlCommand MyCommand=new SqlCommand("select * from 学生信息 where 姓名=@name",MyConnection);
MyCommand.Parameters.Add(new SqlParameter("@name",System.Data.SqlDbType.NChar,18));
MyCommand.Parameters["@name"].Value=TextBox1.Text;
MyConnection.Open();
SqlDataReader dr=MyCommand.ExecuteReader();
if(dr.Read())
{
DataGrid1.DataSource=dr;
this.DataGrid1.DataBind();
MyConnection.Close();
}
else
{
Response.Write("<script>alert('你输入的名字不存在')</script>");
}
}
怎么当数据库中符合条件的数据只有一条时,我的datagrid1没有显示呢?
当数据库中符合条件的数据为n条时,datagrid1中只能读取出n-1条呢?
请各位高手指点一下,在线等
谢了!