Reputation: 417
I am using sql server 2005 and visual stdio 2008 i have a textbox in my page as txtEmailId i want to compare this value in database with email_id column[it is a primary key] to avoid inconsistence in database on a button click with out using custom validator
Upvotes: 0
Views: 16323
Reputation: 417
SOLUTION :>
ValidateQuery = "Select [Email_Id] from Sign_Up where (Email_Id = '"+txtEmailId.Text+"')"; SqlCommand Validatecmd = new SqlCommand(ValidateQuery, con); String validate_email; validate_email= (String)Validatecmd.ExecuteScalar(); if (validate_email != null) { lblValidateEmail.Text = "YOUR EMAIL ID IS REGISTERD TRY DIFFERENT EMAIL ID "; } else { // DO WHAT EVER U WANT }</code>
Upvotes: 0
Reputation: 7276
There are several ways.
1: Do a db query using sqlcommand like below:
SqlDataReader reader = null;
SqlConnection conn = new SqlConnection("Yourconnectionstring");
conn.Open();
SqlCommand cmd = new SqlCommand("select * from yourtable where email_id=@emailid", conn);
cmd.Parameters.AddWithValue("@emailid",txtEmail.Text);
reader = cmd.ExecuteReader();
if(reader!=null && reader.HasRows){
//email exists in db do something
}
Upvotes: 3
Reputation: 4807
My syntax might be off, but is this what you are looking for?
if txtEmailID.Text == email_id
performActionA;
Else
performActionB;
Upvotes: 1