private void button1_Click(object sender, EventArgs e)
{
string name;
name = textBox5.Text;
SqlConnection con10 = new SqlConnection("con strn");
SqlCommand cmd10 = new SqlCommand("select * from sumant where username=@name");
cmd10.Parameters.AddWithValue("@name",name);
cmd10.Connection = con10;
cmd10.Connection.Open();//line 7
SqlDataReader dr = cmd10.ExecuteReader();
}
if ( textBox2.Text == dr[2].ToString())
{
//do something;
}
Kiedy debuguję do linii 7, wszystko jest w porządku, ale po tym dr zgłasza wyjątek:
Invalid attempt to read when no data is present.
Nie jest to możliwe, ponieważ mam dane w tabeli z nazwą użytkownika = sumant. Proszę, powiedz mi, czy stwierdzenie „jeśli” jest poprawne, czy nie…
A jak mam usunąć błąd?