I am working on asp.net c# sqlserver 2005 database.
on my webpage i have a gridview, in this gridview i have 4 fields (Username,Password, email,designation) and 4 textboxes in footer to enter the records. and a add button to add the record.
if the record already exists in database, display a message Username already exists.
Thanks in advance.
This is my code in row command in gridview.
protected void GVRegistrations_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("AddNew Registrations"))
{
TextBox TxtUsername = (TextBox)GVRegistrations.FooterRow.FindControl("TxtFooterUsername");
TextBox TxtPassword = (TextBox)GVRegistrations.FooterRow.FindControl("TxtFooterPassword");
TextBox TxtEmail = (TextBox)GVRegistrations.FooterRow.FindControl("TxtFooterEmail");
TextBox TxtDesignation = (TextBox)GVRegistrations.FooterRow.FindControl("TxtFooterDesignation");
con.Open();
SqlCommand cmd = new SqlCommand("INSERT into ACRegistrations(Username,Password,Email,Designation) values('" + TxtUsername.Text + "','" + TxtPassword.Text + "','" + TxtEmail.Text + "','" + TxtDesignation.Text + "')", con);
int result = cmd.ExecuteNonQuery();
con.Close();
if (result == 1)
{
BindRegistrations();
ScriptManager.RegisterStartupScript(this, this.GetType(), "RunCode", "javascript:alert('Record Added successfully');", true);
}
}
}
here just i want to add to code, that if username already exists. if i enter the same username onceagain.