Проблема подключения, когда emailid существует в базе данных или нет?
Issue With Connection When Working With SSMS. How to Check EmailId Exist in the database or not? <pre><pre> protected void Button1_Click(object sender, EventArgs e) { string firstname = txtFirstName.Text; string lastname = txtLastName.Text; string emailid = txtEmailId.Text; string password = txtclientpassword.Text; Registration_Click(firstname, lastname, emailid, password); } void Registration_Click(string firstname,string lastname,string emailid,string Password) { string conn = ConfigurationManager.ConnectionStrings["connstr"].ToString(); SqlConnection cn = new SqlConnection(conn); cn.Open(); string Insertquery = "Insert into tbladminclient(FirstName,LastName,EmailId,Password) values(@FirstName,@LastName,@EmailId,@Password)"; SqlCommand cmd = new SqlCommand(Insertquery, cn); cmd.CommandType = CommandType.Text; string query = "SELECT * FROM tbladminclient WHERE EmailId='" + txtEmailId.Text + "'"; cmd.Parameters.AddWithValue(query, cn); int count = (int)cmd.ExecuteScalar(); if (count > 0) { Label2.Text = "EmailId is Already In Use"; } cmd.Parameters.AddWithValue("@FirstName", firstname); cmd.Parameters.AddWithValue("@LastName", lastname); cmd.Parameters.AddWithValue("@EmailId", emailid); cmd.Parameters.AddWithValue("@Password", Password); try { int validateOperation = cmd.ExecuteNonQuery(); if (validateOperation > 0) { Response.Write("successfully Registration"); Response.Redirect("ClientLogin.aspx"); } else { Response.Write("Not successfully Registration"); } } catch (SqlException e) { Response.Write("error"); } finally { cn.Close(); } } }
Как определить, существует ли Emailid в базе данных или нет??
Изображение:
Error: <a href="https://imgur.com/a/hzILnC1">Imgur: The magic of the Internet</a>[<a href="https://imgur.com/a/hzILnC1" target="_blank" title="New Window">^</a>]
Что я уже пробовал:
I want the Emailid is already is inserted in the database then not inserted the second time?