Advertisement
Guest User

Untitled

a guest
Apr 20th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. con = new SqlConnection(@"Data Source=MARIA-PC;Initial Catalog=Account;Integrated Security=True");
  4. SqlCommand cmd1 = new SqlCommand("SELECT * FROM [dbo].[Cont] WHERE Username = @Username and Password = @Password;", con);
  5. cmd1.Parameters.AddWithValue("@Username", this.Username.Text);
  6. cmd1.Parameters.AddWithValue("@Password", this.Password.Text);
  7. cmd1.Connection = con;
  8. con.Open();
  9.  
  10. DataSet ds = new DataSet();
  11. SqlDataAdapter da = new SqlDataAdapter(cmd1);
  12. da.Fill(ds);
  13. con.Close();
  14.  
  15. bool loginSuccessful = ((ds.Tables.Count > 0) && (ds.Tables[0].Rows.Count > 0));
  16.  
  17. if (loginSuccessful )
  18. {
  19. MessageBox.Show("You logged in successfully!","Success!");
  20. this.Visible = false;
  21. f3.ShowDialog();
  22. this.Visible = true;
  23. }
  24. else
  25. {
  26. MessageBox.Show("Invalid username or password!", "Error!");
  27. }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement