首页 > 数据库技术 > 详细

事务执行多条sql语句添加

时间:2020-06-27 16:09:34      阅读:129      评论:0      收藏:0      [点我收藏+]

/// <summary>
/// 事务执行多条sql语句添加
/// </summary>
/// <param name="SQLStringList"></param>
/// <returns></returns>
public int ExecuteSqlTran(List<String> SQLStringList)
{
using (SqlConnection conn = new SqlConnection(con))
{
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
SqlTransaction tx = conn.BeginTransaction();
cmd.Transaction = tx;
try
{
int count = 0;
for (int n = 0; n < SQLStringList.Count; n++)
{
string strsql = SQLStringList[n];
if (strsql.Trim().Length > 1)
{
cmd.CommandText = strsql;
count += cmd.ExecuteNonQuery();
}
}
tx.Commit();
return count;
}
catch (Exception err)
{
tx.Rollback();

return 0;
}
}

}

事务执行多条sql语句添加

原文:https://www.cnblogs.com/xr0818/p/13198352.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!