Beispiel #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            this.Hide();
            trangChu form = new trangChu();

            form.Show();
        }
 // Kiểm tra đăng nhập
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         conn = new SqlConnection(strConnection);
         conn.Open();
         string sql = "Select COUNT(*)  FROM [test].[dbo].[admin] where userName=@userName and passWord=@pass ";
         command = new SqlCommand(sql, conn);
         command.Parameters.Add(new SqlParameter("@userName", textBox1.Text));
         command.Parameters.Add(new SqlParameter("@pass", textBox2.Text));
         int x = (int)command.ExecuteScalar();
         if (x == 1) //Kiểm tra userName và passWord có trong database chưa
         {
             //MessageBox.Show("login suzess", "thong bao");
             this.Hide();
             trangChu form = new trangChu();
             form.Show();
         }
         else
         {
             MessageBox.Show("login failt");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     conn.Close();
 }