Sử dụng phương thức ExecuteScalar của đối tượng SqlCommand để kiểm tra đăng nhập trong C#
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);
int i =(Int32)lenh.ExecuteScalar();
if (i>0)
MessageBox.Show("Đang nhập thành công");
else
MessageBox.Show("Đang nhập thất bại");
ketnoi.Close();
}
Tin khác:
- Tìm hiểu quy ước đặt tên thiết bị lưu trữ trong Linux
- Tìm hiểu cấu trúc i-node và cách đọc thông tin tệp tin trong Linux
- Xu hướng mới trong phân tích và thiết kế hệ thống thông tin
- MuZero – Thuật toán Trí tuệ nhân tạo có khả năng tự học mạnh mẽ
- Chủ đề OSCP (Port Redirection and SSH Tunneling) (tiếp theo)