Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.61 KB | None | 0 0
  1.  
  2.         SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Project_Manager.Properties.Settings.Project_ManagerConnectionString"].ConnectionString);
  3.         private void btnOK_Click(object sender, EventArgs e)
  4.         {
  5.             string user;
  6.             user = txtUser.Text;
  7.             string pass;
  8.             pass = txtPass.Text;
  9.             try
  10.             {
  11.                 SqlCommand check = new SqlCommand("SELECT Username, Password FROM tblUsers WHERE Username = @user AND Password = @pass", con);
  12.                 check.Parameters.AddWithValue("@user", user);
  13.                 check.Parameters.AddWithValue("@pass", pass);
  14.                 con.Open();
  15.                 SqlDataReader reader = check.ExecuteReader();
  16.                 if (reader.HasRows)
  17.                 {
  18.                     Form.ActiveForm.Controls["menuStrip1"].Enabled = true;
  19.                     this.Close();
  20.                  //   MessageBox.Show("Logged in as " + user, "Wellcome", MessageBoxButtons.OK, MessageBoxIcon.Information);
  21.                 }
  22.                 else
  23.                 {
  24.                     con.Close();
  25.                     MessageBox.Show("Wrong username or password ", "Error Login Details", MessageBoxButtons.OK, MessageBoxIcon.Error);
  26.                     txtPass.Clear();
  27.                     txtUser.Clear();
  28.                     txtUser.Focus();
  29.                 }
  30.  
  31.             }
  32.             catch (Exception ex)
  33.             {
  34.                 MessageBox.Show("GREEEEEEESKAAAAAAAAAAA" + ex.ToString());
  35.             }
  36.             finally
  37.             {
  38.                
  39.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement