Good Day everyone and thank you in advance.
I am developing a registration webform and having some problem with the code to verify if an e-mail address already exists, before it saves to the database.
this is what i have so far:
When you click register, the code is suppose to search the database for the same email in the textbox (TextBox2) and if the same e-mail address is found change the Label(Label1) text to Find. If not it will specify that it is "not find" and register the user into the database (that code i still need to write).
The problem I have is that it always specify that the email address is "not find" even if it is in the database.
I have tried changing the folllowing:
if (rd[1].ToString() == TextBox2.Text)
if (rd[2].ToString() == TextBox2.Text)
if (rd[3].ToString() == TextBox2.Text)
but the label remains to change to "Not Find".
I am very new to C# and visual studio. only started self learning this month. (just mentioning it.)
Thanks again
I am developing a registration webform and having some problem with the code to verify if an e-mail address already exists, before it saves to the database.
this is what i have so far:
C#:
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = @"Data Source =(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\MAIN.mdf;Integrated Security=True";
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from [Users]";
cmd.Connection = conn;
SqlDataReader rd = cmd.ExecuteReader();
while (rd.Read())
{
if (rd[2].ToString() == TextBox2.Text)
{
flag = true;
break;
}
}
if (flag == true)
Label1.Text = "find";
else
Label1.Text = "nof find";
}
When you click register, the code is suppose to search the database for the same email in the textbox (TextBox2) and if the same e-mail address is found change the Label(Label1) text to Find. If not it will specify that it is "not find" and register the user into the database (that code i still need to write).
The problem I have is that it always specify that the email address is "not find" even if it is in the database.
I have tried changing the folllowing:
if (rd[1].ToString() == TextBox2.Text)
if (rd[2].ToString() == TextBox2.Text)
if (rd[3].ToString() == TextBox2.Text)
but the label remains to change to "Not Find".
I am very new to C# and visual studio. only started self learning this month. (just mentioning it.)
Thanks again