using (SqlConnection con = new SqlConnection(@"Data Source=HUYDUNG123\SQLEXPRESS;Initial Catalog=QLKhachSan;User ID=sa;Password=123456a@"))
{
using (SqlCommand commandtdv = new SqlCommand())
{
try
{
con.Open();
commandtdv.Connection = con; // <== lacking
commandtdv.CommandType = CommandType.Text;
commandtdv.CommandText = "Update Phong set TinhTrang = @TinhTrang where MaPhong='"+label12.Text+"'";
commandtdv.Parameters.AddWithValue("@TinhTrang",0);
}
catch (SqlException)
{
// error here
MessageBox.Show("Lỗi", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
con.Close();
using (SqlCommand commandtdvx = new SqlCommand())
{
try
{
con.Open();
commandtdvx.Connection = con; // <== lacking
commandtdvx.CommandType = CommandType.Text;
commandtdvx.CommandText = "Update DichVu set TinhTrang = @TinhTrang where MaPhong='"+label12.Text +"'";
commandtdv.Parameters.AddWithValue("@TinhTrang", 0);
}
catch (SqlException)
{
// error here
MessageBox.Show("Lỗi", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
con.Close();
MessageBox.Show("Thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
}
Code mình viết như trên, nhưng không hiểu sao không báo lỗi. Nhưng cũng không update được lên SQL. Mong các bạn giúp cho
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?