Can you help me about the syntax in Visual studio C# i want my phone directory that if you enter same data in primary key,it will display a Show message Box that display "already exist" if it is not, it will proceed to normal functions.. well im always trying but i can't figure it out...
con.Open();
if (!dataGridView1.Equals(textBox3.Text))
{
SqlCommand cmd = new SqlCommand (@"INSERT INTO Amer
(First, Last, Mobile, Email, Category)
VALUES ('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + comboBox1.Text + "')",con);
cmd.ExecuteNonQuery();
MessageBox.Show("Saved!");
textBox1.Text = "";
textBox2.Clear();
textBox3.Text = "";
textBox4.Clear();
comboBox1.SelectedIndex = -1;
textBox1.Focus();
Display();
}
else
{
MessageBox.Show("Mobile Number Already Exist!");
textBox1.Text = "";
textBox2.Clear();
textBox3.Text = "";
textBox4.Clear();
comboBox1.SelectedIndex = -1;
textBox1.Focus();
Display();