First, a warning:
What if I typed this into your txt_fname?
');delete telephone;--
Any idea what that might do to your data?
This is called SQL Injection and your code is wide open to it. Use parameterised queries instead. That will protect you from evil:
SqlCommand cmd = new SqlCommand("DELETE from Telephone where (FName= @fname)", con);
cmd.Parameters.Add(new SqlParameter("@fname",SqlDbType.VarChar){Value=txt_fname.Text}));
On with your question.
I assume you don't get any error messages so you have to add more debug info, like this:
private void btn_delete_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("DELETE from Telephone where (FName= @fname)", con);
cmd.Parameters.Add(new SqlParameter("@fname",SqlDbType.VarChar){Value=txt_fname.Text}));
int rowsAffected = cmd.ExecuteNonQuery();
con.Close();
if(rowsAffected==1)
MessageBox.Show("Contact Deleted...");
else
MessageBox.Show(string.Format("Problem with delete: {0} records deleted.\n Query:'{1}', Parameter @fname='{2}'",rowsAffected,cmd.CommandText,txt_fname.Text));
Display();
}
If zero or more that one records are updated then the message should read:
Problem with delete: 0 records deleted.
Query:'DELETE from Telephone where (FName= @fname)', "Parameter @fname='SomeTextThatDidn'tWork'
PS: also, your query has whitespace around the parameter:
"FName= ' " + txt_fname.Text + " ')"
"FName= '" + txt_fname.Text + "')"
Using parameters will prevent this also