我有一个表格,我只想检查该用户是否已经存在,如果不存在,则保存在数据库中,否则显示错误消息用户已经存在知道这个问题我问了很多次,但我没有找到我的解决方案asp代码:
protected void btnSubmit_Click(object sender, EventArgs e)
{
con.Open();
string FirstName = tbFirstName.Text;
string LastName = tbLastName.Text;
string Email = tbEmail.Text;
string Pass = tbPass.Text;
string ConfirmPass = tbConfirmPass.Text;
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = "Insert into UserDetails(@FirstName,@LastName,@Email,@Pass,@ConfirmPass)values('" + tbFirstName.Text + "','" + tbLastName.Text + "','" + tbEmail.Text + "','" + tbPass.Text + "','" + tbConfirmPass.Text + "')";
cmd.Parameters.AddWithValue("@FirstName", tbFirstName.Text.Trim());
cmd.Parameters.AddWithValue("@LastName", tbLastName.Text.Trim());
cmd.Parameters.AddWithValue("@Email", tbEmail.Text.Trim());
cmd.Parameters.AddWithValue("@Pass", tbPass.Text.Trim());
cmd.Parameters.AddWithValue("@ConfirmPass", tbConfirmPass.Text.Trim());
}
con.Close();
tbFirstName.Text = "";
tbLastName.Text = "";
tbEmail.Text = "";
tbPass.Text = "";
tbConfirmPass.Text = "";
tbFirstName.Focus();
}
在此按钮用户的单击事件中只能创建,但我想验证它是否存在于数据库中