(+84) 236.3827111 ex. 402

Sử dung phương thức ExecuteReader() trong SqlCommand để kiểm tra đăng nhập


privatevoid button1_Click(object sender, EventArgs e)

{

string chuoiketnoi = @"server =SCD081815; database = thuchanh;integrated security=true;";

SqlConnection ketnoi = new SqlConnection();

ketnoi.ConnectionString = chuoiketnoi;

ketnoi.Open();

SqlCommand lenh = new SqlCommand();

lenh.Connection = ketnoi;

lenh.CommandText = string.Format("select count(*) from Sinhvien where masv ='{0}' and pass = '{1}'", textBox1.Text, textBox2.Text);

SqldataReader reader = lenh.ExecuteReader();

if (reader.HasRow==true)

MessageBox.Show("Đang nhập thành công");

else

MessageBox.Show("Đang nhập thất bại");

ketnoi.Close();

}