-
回复 @ siki: 老师 麻烦帮我看下 这个问题在哪 事务是不是最多一次1000条啊 判断后只插入了1000条 就显示transition has already been committed or is not pending
cmd.Transaction = conn.BeginTransaction();//开启一个数据库事务
try {
for (int i = 0; i < mysql.Length; i++)
{
if (mysql[i] == null || mysql[i] == "")
{
continue;
}
cmd.CommandText = mysql[i];
cmd.ExecuteNonQuery();
if ((i > 0 && i % 500 == 0) || i == mysql.Length - 1) {
cmd.Transaction.Commit();
cmd.Transaction = conn.BeginTransaction();
}
}
}
catch (Exception e) {
Console.WriteLine(e);
mt.Rollback();//事务回滚
Console.ReadKey();
}