Advertisement
Guest User

lgn

a guest
Sep 24th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. SqlConnection sqlCon = new SqlConnection("Data Source=DESKTOP-N2I1H66 ; Initial Catalog=PassBox; Integrated Security=True");
  2. string sql = "Select * from userInfo where UserName=@u and Password=@p";
  3. SqlCommand con = new SqlCommand(sql,sqlCon);
  4. con.Parameters.AddWithValue("@u", txtUsername.Text);
  5. con.Parameters.AddWithValue("@p",txtPass.Text);
  6. try
  7. {
  8.  
  9. sqlCon.Open();
  10. SqlDataAdapter sqda = new SqlDataAdapter(con);
  11. DataSet dataset = new DataSet();
  12. sqda.Fill(dataset);
  13. sqlCon.Close();
  14. int i = dataset.Tables[0].Rows.Count;
  15. if (i == 1)
  16. {
  17. MainLogin ml = new MainLogin();
  18. ml.Show();
  19. ml.Text = "Logged in as : " + txtUsername.Text;
  20.  
  21. this.Hide();
  22.  
  23.  
  24. }else
  25. {
  26. MessageBox.Show("Login Failed . Check Username & Password");
  27.  
  28. txtUsername.Focus();
  29. }
  30.  
  31. }
  32. catch(Exception couldntconnect)
  33. {
  34. MessageBox.Show("Couldn't Connect");
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement