开发者

how to compare a value from database with the textbox value

I am using sql server 2005 and visual stdio 2008 i have a textbo开发者_运维技巧x 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


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
    }


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

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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜