Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- string gender = string.Empty;
- if (rbMale.Checked)
- {
- gender = "M";
- }
- else if (rbFemale.Checked)
- {
- gender = "F";
- }
- try
- {
- SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
- con.Open();
- string query = "select count(*) from userTable where username = '" + username.Text + "'";
- SqlCommand cmd = new SqlCommand(query, con);
- int check = Convert.ToInt32(cmd.ExecuteScalar().ToString());
- if(check > 0) {
- errMsg.Visible = true;
- errMsg.ForeColor = System.Drawing.Color.Red;
- errMsg.Text = "Username has been taken!";
- }
- else
- {
- string query1 = "insert into userTable (fname,lname,gender,country,email,username,password,usertype) values (@fname,@lname,@gender,@country,@email,@username,@password,@usertype)";
- SqlCommand cmd1 = new SqlCommand(query1, con);
- cmd1.Parameters.AddWithValue("@fname", fname.Text);
- cmd1.Parameters.AddWithValue("@lname", lname.Text);
- cmd1.Parameters.AddWithValue("@gender", gender);
- cmd1.Parameters.AddWithValue("@country", country.Text);
- cmd1.Parameters.AddWithValue("@email", email.Text);
- cmd1.Parameters.AddWithValue("@username", username.Text);
- cmd1.Parameters.AddWithValue("@password", pwd.Text);
- cmd1.Parameters.AddWithValue("@usertype", admin.Text);
- cmd1.ExecuteNonQuery();
- Response.Redirect("login.aspx");
- }
- con.Close();
- }
- catch(Exception ex)
- {
- errMsg.Visible = true;
- errMsg.ForeColor = System.Drawing.Color.Red;
- errMsg.Text = "Regostration not successgul!" + ex.ToString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement