private void button4_Click(object sender, EventArgs e)
{
String s = "data
source=ACER-PC\\SQLEXPRESS;database = hr;integrated security = SSPI";
SqlConnection c = new SqlConnection(s);
try{
c.Open();
}
catch (SqlException exp){
string a = exp.Message;
}
SqlTransaction objTrans = c.BeginTransaction(IsolationLevel.ReadCommitted);
try {
SqlCommand cmd = c.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.Transaction = objTrans;
cmd.CommandText = "DELETE tblEmployees WHERE id=(" + textBox1.Text + ")";
cmd.ExecuteNonQuery();
objTrans.Commit();
Console.WriteLine("Transaction
Committed\n");
}
catch (SqlException ex){
objTrans.Rollback();
MessageBox.Show(ex.Message);
}
}
Tidak ada komentar:
Posting Komentar