Monday 18 February 2013

check if record already exists access



SqlConnection con = new SqlConnection(strConnString);
            SqlCommand cmdCount = new SqlCommand("select count(*) from customers where name='" + txtCustomername.Text + "'", con);
            con.Open();
            int count = (int)cmdCount.ExecuteScalar();
            if (count > 0)
            {
                lblMessage.Text = "Customer already exists";
                lblMessage.Visible = true;
            }
            else
            {
                Insert query
            }
            con.Close();

No comments:

Post a Comment