to show an error message while entering duplicates when column is primary key
<p>As in table named Emp i have Name Column is Primary key,when i add duplicate name like (Bharat Mali) which is already present in database,this record is not get added in database,but showing me this message( employee added successfully) i want to show a message to user like(duplicate values can't be stored).
 I am using this code behind Add button Click</p>

<pre><code>private void button3_Click(object sender, EventArgs e)
        {
            DBHandling db = new DBHandling();
            if (name.Text.Trim().Equals("")&amp;&amp; name.Text.Trim().Equals("select Emp.name from Emp"))
            {
                name.Focus();
                MessageBox.Show("Name cannot be blank or same!");
            }
            else if(Payment.Text.Trim().Equals(""))
            {
                Payment.Focus();
                MessageBox.Show("Payment cannot be blank!");
            }
            else if (!IsNumeric(Payment.Text.Trim()))
            {
                Payment.Focus();
                MessageBox.Show("Payment should contain Numerical Values!");
            }
                else if(CellNumber.Text.Trim().Equals(""))
            {
                CellNumber.Focus();
                MessageBox.Show("Cell Number cannot be blank!");

            }
            else if (!IsNumeric(CellNumber.Text.Trim()) || CellNumber.Text.Trim().Length&lt;10)
            {
                CellNumber.Focus();
                MessageBox.Show("Invalid Cell Number!");
            }
            else if(JoiningDate.Text.Trim().Equals(""))
            {
                JoiningDate.Focus();
                MessageBox.Show("set Joining Date!");
            }             
            else
            {
                db.AddEmp(name.Text, Payment.Text, CellNumber.Text, Education.Text, JoiningDate.Text);
                MessageBox.Show("Employee added successfully!");
            }
            name.Clear();           
            Payment.Clear();           
            CellNumber.Clear();            
            Education.Clear();
            name.Focus();

        }
</code></pre>

<p>so how should i do it ,thanks . </p>

<p>I am checking PK using this below line of code ,I am not getting any answer for this but not even an error,do you know any other way that how should i do it?</p>

<pre><code>if (name.Text.Trim().Equals("")&amp;&amp; name.Text.Trim().Equals("select Emp.name from Emp"))
                {
                    name.Focus();
                    MessageBox.Show("Name cannot be blank or same!");
                }
</code></pre>
