SqlConnection con = DB.creatCon();
con.Open();
SqlCommand cmd = new SqlCommand("select cusTel,cusEmail from personCus where cusID=" + this.dropPerName.SelectedValue.ToString(), con);
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
this.txtPerTel.Text = sdr[0].ToString();
this.txtPerEmail.Text = sdr[1].ToString();
}
sdr.Close();
con.Close();
上面这段代码,如果把if(sdr.Read())去掉后,明明有数据,它也会报错说不能读空数据,请问这是为什么?
con.Open();
SqlCommand cmd = new SqlCommand("select cusTel,cusEmail from personCus where cusID=" + this.dropPerName.SelectedValue.ToString(), con);
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
this.txtPerTel.Text = sdr[0].ToString();
this.txtPerEmail.Text = sdr[1].ToString();
}
sdr.Close();
con.Close();
上面这段代码,如果把if(sdr.Read())去掉后,明明有数据,它也会报错说不能读空数据,请问这是为什么?
System.Diagnostics.Debug.Print("select cusTel,cusEmail from personCus where cusID=" + this.dropPerName.SelectedValue.ToString() );-----------------------
SqlConnection con = DB.creatCon();
con.Open();
SqlCommand cmd = new SqlCommand("select cusTel,cusEmail from personCus where cusID=" + this.dropPerName.SelectedValue.ToString(), con);
System.Diagnostics.Debug.Print("select cusTel,cusEmail from personCus where cusID=" + this.dropPerName.SelectedValue.ToString() );
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
this.txtPerTel.Text = sdr[0].ToString();
this.txtPerEmail.Text = sdr[1].ToString();
}
sdr.Close();
con.Close();