首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

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

2012-05-20 
C#事务处理疑问C# code Liststring sqlList new Liststring()sqlList.Add(update pictures set rem

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

热点排行