i use c# and asp.net , when the user create new account will enter email and national id as primary key then if user click (VIRIFY ME) button ,the program will store this info in sql server , and send email msg to the user , but my problem it when the user click on varify me button more than one it will print (email is already exist)
protected void Button1_Click2(object sender, EventArgs e)
{
LabelErrorMSG.Text = "";
String email = emailtextbox0.Text.Trim();
String notionalID = textbox_National_ID.Text.Trim();
try
{
if (notionalID != "" && email != "" && counter==1)
{
// insert notional ID and email into database
getdataobj.PageSignUpInsert(notionalID, email);
/////////////////////////////////////////////////////////////////////
conn.Open();
//Generate Verification Code
String code = getdataobj.GetRandomNumber().ToString();
// Set Verification Code in database
SqlCommand comm = new SqlCommand("UPDATE trained SET VerificationCode='" + code + "' where NationalID='" + notionalID + "'", conn);
comm.ExecuteNonQuery();
conn.Close();
//Send Email to the user with Verification Code
SmtpClient smtpClient = new SmtpClient();
MailMessage mailMessage = new MailMessage("saudiasummertraining@gmail.com", email, "", "");
mailMessage.To.Add(new MailAddress(email));
mailMessage.Subject = "Saudia Summer Traning";
mailMessage.Body = code;
smtpClient.EnableSsl = true;
smtpClient.Send(mailMessage);
Panel1.Visible = true;
}
else
{
LabelErrorMSG.Text = "you must insert national ID and email ";
}
////////////////////////////////////////////////////////////////////
}
catch (SqlException ex)
{
if (ex.Number == 2627)
{
if (ex.Message.Contains("UNIQUE"))
{
///error msg regarding Unique key violation.
LabelErrorMSG.Text = "The email already exist ";
}
if (ex.Message.Contains("PRIMARY"))
{
//error msg regarding Primary key violation.
LabelErrorMSG.Text = "The national ID already exist ";
}
}
}
}