private void button2_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 sqltran = c.BeginTransaction(IsolationLevel.ReadCommitted);
try
{
StringBuilder sb = new StringBuilder();
sb.Append("INSERT INTO tblEmployees VALUES('" + textBox1.Text + "','" + textBox2.Text + "')");
SqlCommand com = new SqlCommand(sb.ToString(), c);
com.Transaction = sqltran;
com.ExecuteNonQuery();
sqltran.Commit();
}
catch (SqlException ex)
{
sqltran.Rollback();
MessageBox.Show(ex.Message);
}
}
Tidak ada komentar:
Posting Komentar