Advertisement
Guest User

Untitled

a guest
Sep 8th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3.  
  4. SqlConnection conn = new SqlConnection(@"Data source=.;Initial Catalog=msdb;username=lu;password=lu");
  5. SqlCommand cmd = new SqlCommand("select * from login where username=@username and password=@password", conn);
  6.  
  7. cmd.Parameters.AddWithValue("@username", textBox1.Text);
  8. cmd.Parameters.AddWithValue("password", textBox2.Text);
  9. SqlDataAdapter sda = new SqlDataAdapter(cmd);
  10. DataTable dt = new DataTable();
  11. sda.Fill(dt);
  12. conn.Open();
  13. int i = cmd.ExecuteNonQuery();
  14. conn.Close();
  15.  
  16. if (dt.Rows.Count > 0)
  17. {
  18. HttpContext.Current.Session["id"] = textBox1.Text;
  19. HttpContext.Current.Response.Redirect("LoginPage.cs");
  20. HttpContext.Current.Session.RemoveAll();
  21.  
  22. }
  23. else
  24. {
  25. label1.Text = "your username or password is incorrect";
  26. label1.ForeColor = System.Drawing.Color.Red;
  27. }
  28. }
  29.  
  30. cmd.Parameters.AddWithValue("password", textBox2.Text);
  31. it should be
  32. cmd.Parameters.AddWithValue("@password", textBox2.Text);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement