using
(SqlConnection conn =
new
SqlConnection(
"連線字串"
))
02.
{
03.
conn.Open();
04.
SqlCommand myCommand = conn.CreateCommand();
05.
SqlTransaction trans = conn.BeginTransaction(IsolationLevel.ReadCommitted);
06.
07.
myCommand.Connection = conn;
08.
myCommand.Transaction = trans;
09.
10.
try
11.
{
12.
//要執行的SQL
13.
//INSERT INTO xxx (x,x,x) VALUES (x,x,x)
14.
myCommand.ExecuteNonQuery();
15.
16.
//INSERT INTO yyy (y,y,y) VALUES (y,y,y)
17.
myCommand.ExecuteNonQuery();
18.
19.
trans.Commit();
20.
21.
}
22.
catch
(Exception e)
23.
{
26.
trans.Rollback();
27.
}
28.
}
沒有留言:
張貼留言