/// <summary>
/// 执行多条SQL语句,实现数据库事务。
/// </summary>
/// <param name="SQLStringList">多条SQL语句</param>
public int ExecuteSqlTran(List<String> SQLStringList)
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
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
{
tx.Rollback();
return 0;
}
}
}
///
create procedure [dbo].[p_suspend_business] |
03 | @Bfixednum varchar (40) |
08 | declare @messageNumber int |
09 | select @SNumber=SNumber from sendnumber where Bfixednum=@Bfixednum |
10 | select @messageNumber = count (@Bfixednum) from [message] where Bfixednum = @Bfixednum and mDate between ( select dateadd(dd,- day (getdate())+1,getdate())) and ( select dateadd(dd,- day (getdate()),dateadd(m,1,getdate()))) |
14 | if (@SNumber is null or @messageNumber = '' ) |
16 | raiserror( '错误!缺少参数 ,请检查!' ,16,1) |
21 | if (@messageNumber >= @SNumber) |
23 | update dbo.Business set BState=0 where Bfixednum=@Bfixednum |
来源