0

I`m trying to make command work but it doesnt work help please. this error appears at cmd("delete

i have sqlcommand cmd;

private void DeleteRecordBtn_Click(object sender, EventArgs e)
    {
        cmd("delete blacklist1 where idnumber=@Idnumber", con);
        con.Open();
        cmd.Parameters.AddWithValue("@idnumber", UID.Text);
        cmd.ExecuteNonQuery();
        con.Close();

    }
Luka
  • 15
  • 1
  • 5

1 Answers1

2

This line:

cmd("delete blacklist1 where idnumber=@Idnumber", con);

Should be:

cmd = new SqlCommand("delete blacklist1 where idnumber=@Idnumber", con);

However, you should put this inside a using block in order to release cmd resources once it finish. See: SqlCommand with using statement

Oscar
  • 13,594
  • 8
  • 47
  • 75