循环执行sql 语句,一起提交,多行的时候总是在等待状态,一行就没有问题
public static Boolean ExecuteQuery(string ConnectionSql, string[] ExeuteSql)//这里有个sql 语句string数组 {
Boolean Rtn=true;
SqlConnection _SqlConn = new SqlConnection(ConnectionSql);
_SqlConn.Open();
SqlTransaction trans = _SqlConn.BeginTransaction();
try
{
foreach (string sql in ExeuteSql)
{
if (sql.Trim() != "")
{
ExecuteQueryEnd(_SqlConn, trans, sql);//执行下面的方法,到后面一起提交,防止出现有的提交有的不能提交的问题
}
else
{
continue;
}
}
();
}
catch (System.Data.SqlClient.SqlException e)
{
trans.Rollback();
Rtn = false;
throw new Exception(e.Message);
}
_SqlConn.Close();
return Rtn;
}
public static void ExecuteQueryEnd(SqlConnection conn, SqlTransaction str,string sqlcmd)
{
SqlCommand _Scmd = new SqlCommand(sqlcmd,conn);
_Scmd.Transaction = str;
_ = CommandType.Text;
_ = 6000;
try
{
_Scmd.ExecuteNonQuery();
}
catch
{
str.Rollback();
} }