ADO.NET事务

在C#中直接使用SQL事务

string conString = "";

SqlConnection conn = new SqlConnection(conString);

conn.Open();

SqlTransaction tran = conn.BeginTransaction();

SqlCommand cmd = new SqlCommand();

cmd.Connection = conn;

cmd.Transaction = tran;

try

{

cmd.CommandText = "";

........

cmd.CommandText  = "";

.......

tran.Commit();

}

catch

{

tran.Rollback();

}

finally

{

conn.Close()

}

posted @ 2012-11-02 12:07  Mark_ybh  阅读(134)  评论(0编辑  收藏  举报