I keep having the following error:
ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.
I am not able to insert into my database as well.
private void btnXoa_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(chuoiKetnoi);
if (MessageBox.Show("Bạn có chắc chắn muốn xóa ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
// Thuc hien xoa du lieu
string delete = "delete from tblKET_QUA where MaSV='" + txtMaSinhVien.Text + "' and MaMH='" + cbbMonHoc.Text + "' ";
using SqlCommand cmd = new SqlCommand(delete, conn);
cmd.ExecuteNonQuery();
MessageBox.Show("Xóa dữ liệu thành công", "Thông báo!");
// Trả tài nguyên
cmd.Dispose();
//Load lai du lieu
load();
}
}