Advertisement
backlight0815

Untitled

Dec 28th, 2022
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. {
  2.  
  3. string gender = string.Empty;
  4. if (rbMale.Checked)
  5. {
  6. gender = "M";
  7. }
  8. else if (rbFemale.Checked)
  9. {
  10. gender = "F";
  11. }
  12. try
  13. {
  14. SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
  15. con.Open();
  16.  
  17. string query = "select count(*) from userTable where username = '" + username.Text + "'";
  18. SqlCommand cmd = new SqlCommand(query, con);
  19. int check = Convert.ToInt32(cmd.ExecuteScalar().ToString());
  20.  
  21. if(check > 0) {
  22. errMsg.Visible = true;
  23. errMsg.ForeColor = System.Drawing.Color.Red;
  24. errMsg.Text = "Username has been taken!";
  25.  
  26. }
  27. else
  28. {
  29. string query1 = "insert into userTable (fname,lname,gender,country,email,username,password,usertype) values (@fname,@lname,@gender,@country,@email,@username,@password,@usertype)";
  30.  
  31. SqlCommand cmd1 = new SqlCommand(query1, con);
  32.  
  33. cmd1.Parameters.AddWithValue("@fname", fname.Text);
  34. cmd1.Parameters.AddWithValue("@lname", lname.Text);
  35. cmd1.Parameters.AddWithValue("@gender", gender);
  36. cmd1.Parameters.AddWithValue("@country", country.Text);
  37. cmd1.Parameters.AddWithValue("@email", email.Text);
  38. cmd1.Parameters.AddWithValue("@username", username.Text);
  39. cmd1.Parameters.AddWithValue("@password", pwd.Text);
  40. cmd1.Parameters.AddWithValue("@usertype", admin.Text);
  41. cmd1.ExecuteNonQuery();
  42. Response.Redirect("login.aspx");
  43. }
  44. con.Close();
  45.  
  46.  
  47.  
  48. }
  49. catch(Exception ex)
  50. {
  51. errMsg.Visible = true;
  52. errMsg.ForeColor = System.Drawing.Color.Red;
  53. errMsg.Text = "Regostration not successgul!" + ex.ToString();
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement