在这段代码中,我有一个按钮点击事件.每当我第一次点击按钮时,代码都能正常工作.但是,如果我在其他时间单击该按钮则会抛出错误.
我的代码是
private void button2_Click(object sender, EventArgs e)
{
string itemname = comboBox1.SelectedItem.ToString();
con.Open();
command.CommandText = "DELETE FROM pricedata WHERE Item=@item";
command.Connection = con;
command.Parameters.AddWithValue("@item", itemname);
command.ExecuteNonQuery();
con.Close();
}
Run Code Online (Sandbox Code Playgroud)