0

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

1
  • 1
    can you please elaborate what do you mean by "avoid inconsistence on a button click" Commented Dec 19, 2010 at 16:15

3 Answers 3

3

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
    }
Sign up to request clarification or add additional context in comments.

Comments

1

My syntax might be off, but is this what you are looking for?

if txtEmailID.Text == email_id
performActionA;
Else
performActionB;

Comments

0
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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.