事务执行多条sql语句添加

/// <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语句添加

上一篇:MySQL-存储过程


下一篇:记MongoDB的安装