110,538
社区成员
发帖
与我相关
我的任务
分享
public static bool ExecuteTransaction(string[] arraySql)
{
SqlConnection conn = new SqlConnection(sqlConnection);
conn.Open();
SqlTransaction transaction = conn.BeginTransaction("Test");
try
{
for(int i = 0; i < arraySql.Length; i++)
{
DataEngine.Instance.ExecuteSQL(transaction, arraySql[i]);
}
transaction.Commit();
conn.Close();
}
catch
{
try
{
transaction.Rollback();
}
catch
{
}
conn.Close();
return false;
}
return true;
}
// 共用 transaction 中的连接
public static int ExecuteSQL(SqlTransaction transaction, string sql)
{
SqlCommand command1 = new SqlCommand();
command.Connection = transaction.Connection;
command.CommandText = sql;
command.Transaction = transaction;
command.CommandType = CommandType.Text;
return command1.ExecuteNonQuery();
}