From 54b082e75b27b2eccf72ca7e0f85344cdf850246 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Tue, 12 Sep 2017 18:56:01 +0800 Subject: [PATCH] - --- .../Abstract/AdoProvider/AdoProvider.cs | 98 ++++++++++++------- 1 file changed, 64 insertions(+), 34 deletions(-) diff --git a/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs index 3853a15ef..808841c0b 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs @@ -227,16 +227,26 @@ namespace SqlSugar #region Core public virtual int ExecuteCommand(string sql, params SugarParameter[] parameters) { - if (this.ProcessingEventStartingSQL != null) - ExecuteProcessingSQL(ref sql, parameters); - ExecuteBefore(sql, parameters); - IDbCommand sqlCommand = GetCommand(sql, parameters); - int count = sqlCommand.ExecuteNonQuery(); - if (this.IsClearParameters) - sqlCommand.Parameters.Clear(); - ExecuteAfter(sql, parameters); - if (this.IsClose()) this.Close(); - return count; + try + { + if (this.ProcessingEventStartingSQL != null) + ExecuteProcessingSQL(ref sql, parameters); + ExecuteBefore(sql, parameters); + IDbCommand sqlCommand = GetCommand(sql, parameters); + int count = sqlCommand.ExecuteNonQuery(); + if (this.IsClearParameters) + sqlCommand.Parameters.Clear(); + ExecuteAfter(sql, parameters); + return count; + } + catch (Exception ex) + { + throw ex; + } + finally + { + if (this.IsClose()) this.Close(); + } } public virtual IDataReader GetDataReader(string sql, params SugarParameter[] parameters) { @@ -255,33 +265,53 @@ namespace SqlSugar } public virtual DataSet GetDataSetAll(string sql, params SugarParameter[] parameters) { - if (this.ProcessingEventStartingSQL != null) - ExecuteProcessingSQL(ref sql, parameters); - ExecuteBefore(sql, parameters); - IDataAdapter dataAdapter = this.GetAdapter(); - IDbCommand sqlCommand = GetCommand(sql, parameters); - this.SetCommandToAdapter(dataAdapter, sqlCommand); - DataSet ds = new DataSet(); - dataAdapter.Fill(ds); - if (this.IsClearParameters) - sqlCommand.Parameters.Clear(); - ExecuteAfter(sql, parameters); - if (this.IsClose()) this.Close(); - return ds; + try + { + if (this.ProcessingEventStartingSQL != null) + ExecuteProcessingSQL(ref sql, parameters); + ExecuteBefore(sql, parameters); + IDataAdapter dataAdapter = this.GetAdapter(); + IDbCommand sqlCommand = GetCommand(sql, parameters); + this.SetCommandToAdapter(dataAdapter, sqlCommand); + DataSet ds = new DataSet(); + dataAdapter.Fill(ds); + if (this.IsClearParameters) + sqlCommand.Parameters.Clear(); + ExecuteAfter(sql, parameters); + return ds; + } + catch (Exception ex) + { + throw ex; + } + finally + { + if (this.IsClose()) this.Close(); + } } public virtual object GetScalar(string sql, params SugarParameter[] parameters) { - if (this.ProcessingEventStartingSQL != null) - ExecuteProcessingSQL(ref sql, parameters); - ExecuteBefore(sql, parameters); - IDbCommand sqlCommand = GetCommand(sql, parameters); - object scalar = sqlCommand.ExecuteScalar(); - scalar = (scalar == null ? 0 : scalar); - if (this.IsClearParameters) - sqlCommand.Parameters.Clear(); - ExecuteAfter(sql, parameters); - if (this.IsClose()) this.Close(); - return scalar; + try + { + if (this.ProcessingEventStartingSQL != null) + ExecuteProcessingSQL(ref sql, parameters); + ExecuteBefore(sql, parameters); + IDbCommand sqlCommand = GetCommand(sql, parameters); + object scalar = sqlCommand.ExecuteScalar(); + scalar = (scalar == null ? 0 : scalar); + if (this.IsClearParameters) + sqlCommand.Parameters.Clear(); + ExecuteAfter(sql, parameters); + return scalar; + } + catch (Exception ex) + { + throw ex; + } + finally + { + if (this.IsClose()) this.Close(); + } } #endregion