In trying to sign up as a new user, I wanted to make sure that two records off the same data will not be inserted into the table.
For example, if I sign up with an email address ID like williams@gmail.com and a business name as Williams no other person will be able to sign up with the same credentials. Even if the email ID is different, the business name should not be registered twice. So these two data should be different.
This is what I came up with; the C# code that will detect an existing email and business name. If they exist, then it should alert that the two records already exists. From this my C# code, it only works for one textbox. When signing up, the code only recognizes one data in textbox, it does not work on two textboxes. So if I sign up, the record will be successfully inserted.
How can it work on the two data when value of the two textboxes inserted already exists?
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Dataregister.mdf;Integrated Security=True");
SqlDataReader dr;
using (SqlCommand cmd = new SqlCommand())
{
cmd.Parameters.Clear();
cmd.CommandText = "SELECT * FROM Users WHERE email=@email AND Name=@Name";
cmd.Parameters.AddWithValue("@email", mailtxtbx.Text);
cmd.Parameters.AddWithValue("@Name", txtname.Text);
cmd.Connection = con;
con.Open();
dr = cmd.ExecuteReader();
}
if (dr.HasRows)
{
dvMessage.Visible = true;
Div1.Visible = false;
lblMessage.Text = "User Already Exists";
lblMessage.ForeColor = System.Drawing.Color.Red;
mailtxtbx.Text = "";
lblsuccess.Visible = false;
lblMessage.Visible = true;
//Label3.Visible = false;
}