Hi Frnds,
I want to validate records, if it already exists show message Record already exists.
If it is new record, it must insert.
In this i have 3 fields as Username,EmployeeNumber, Email.
Existing username must not be inserted once again.
Existing must not be inserted once again.
Existing Email must not be inserted once again.
so it should validate, when add button clicks in gridview footer.
--------------------------------
So, this is my code....
protected void GVRegistrations_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("AddNew Registrations"))
{
TextBox TxtUserName= (TextBox)GVRegistrations.FooterRow.FindControl("TxtFOOTERUserName");
TextBox EmployeeNumber= (TextBox)GVRegistrations.FooterRow.FindControl("TxtFOOTEREmpNo");
TextBox TxtEmail = (TextBox)GVRegistrations.FooterRow.FindControl("TxtFOOTEREmail");
con.Open();
SqlCommand cmd = new SqlCommand("SELECT Count(*) FROM ACRegistrations where UserName= '" + TxtUserName.Text + "'", con);
int count = int.Parse(cmd.ExecuteScalar() + "");
if (count == 0)
{
cmd = new SqlCommand("INSERT into ACRegistrations(UserName,EmployeeNumber,Email) values('" + TxtUserName.Text + "','" + EmployeeNumber.Text + "','" + TxtEmail.Text + "')", con);
int result = cmd.ExecuteNonQuery();
if (result == 1)
{
BindRegistrations();
ScriptManager.RegisterStartupScript(this, this.GetType(), "RunCode", "javascript:alert('Record Added successfully');", true);
}
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "RunCode", "javascript:alert('Sorry, This Record already exists');", true);
}
}
con.Close();
}
I want to validate three fields, one after the other
Please help me, Thanks in advance.