读书人

C#事务处理疑问,该怎么处理

发布时间: 2012-05-20 16:03:12 作者: rapoo

C#事务处理疑问

C# code
 List<string> sqlList= new List<string>();                sqlList.Add("update pictures set remark='testb' where infouuid='test'");                sqlList.Add("update pictures set remarkf='testb' where infouuid='test0'");                sqlList.Add("update pictures set remark='testb' where infouuid='test2'");      using (DbConnection connection = GetConnection())            {                connection.Open();                DbTransaction transaction = connection.BeginTransaction();                DbCommand cmd = connection.CreateCommand();                cmd.Transaction = transaction;                foreach (string strSql in sqlList)                {                    if (!string.IsNullOrEmpty(strSql))                    {                        cmd.CommandText = strSql;                        cmd.ExecuteNonQuery();                    }                }                transaction.Commit();            }

代码如上:1,3语句正确,2语句有错误。 我希望3条更新语句要么全部执行成功,只要有一条出错就回滚。但实际是1执行成功了,到2出错后,并没有回滚。数据库用的MySql。


[解决办法]
ISAM、MyISAM两种类型的表不支持事务

读书人网 >C#

热点推荐