Using Stored Procedure


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. protected void btnSubmit_Click(object sender, EventArgs e)
  2. {
  3. string connectionString = ConfigurationManager.ConnectionStrings["dragSlips_dbConnectionString"].ConnectionString;
  4.  
  5. using (SqlConnection myConnection = new SqlConnection(connectionString))
  6. {
  7. SqlCommand login = new SqlCommand();
  8. login.Connection = myConnection;
  9.  
  10. myConnection.Open();
  11.  
  12. login.Parameters.AddWithValue("@username", txtUsername.Text);
  13. login.Parameters.AddWithValue("@password", txtPassword.Text);
  14.  
  15. login.CommandText = "[login]";
  16. login.CommandType = System.Data.CommandType.StoredProcedure;
  17.  
  18. object myResult = login.ExecuteScalar();
  19.  
  20. if (Convert.ToInt32(myResult) == 0)
  21. {
  22. lblLoggedIn.Text = "try again!";
  23. }
  24. else
  25. {
  26. Response.Redirect("admin.aspx");
  27. }
  28.  
  29. //MyConnection
  30.  
  31. myConnection.Close();
  32.  
  33. }
  34. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.