日期:2014-05-18  浏览次数:20725 次

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两种类型的表不支持事务