码迷,mamicode.com
首页 > 数据库 > 详细

C# 使用MySQL事务的使用方法

时间:2015-01-07 18:24:28      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:

 

//使用事务来处理多条数据,如果不成功则回滚

public void getCheckListSubmit()
{
string _conStr = "................";//连接字符串
OdbcConnection _odbcCon = new OdbcConnection(_conStr);
_odbcCon.Open();

OdbcTransaction trans = _odbcCon.BeginTransaction(IsolationLevel.ReadCommitted);
OdbcCommand cmd = new OdbcCommand();
cmd.Connection = trans.Connection;
cmd.Transaction = trans;

string sqlStr = "";
try
{
sqlStr = ".................";

cmd.CommandText = sqlStr;
cmd.ExecuteNonQuery();

sqlStr2 = ".................";
cmd.CommandText = sqlStr2;
cmd.ExecuteNonQuery();

}
catch
{
trans.Rollback();
hidsysMsg.Value = "Insert Failed";
_odbcCon.Close();
return;
}
trans.Commit();
hidsysMsg.Value = "Insert Succeeded";
_odbcCon.Close();

}

C# 使用MySQL事务的使用方法

标签:

原文地址:http://www.cnblogs.com/a-mumu/p/4208957.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!