public string ExecuteProcedure(SqlCommandObject SQLobj, out DataTable dt) { dt = new DataTable(); try { OpenConnection(); SqlCommand cmd = new SqlCommand(SQLobj.SPName, con); if (SQLobj.SPParams != null) { foreach (DbParameter dbParameter in SQLobj.SPParams) { SqlParameter parameter = new SqlParameter(); parameter.ParameterName = "@" + dbParameter.ParameterName; parameter.DbType = dbParameter.DbType; //parameter.Size = dbParameter.Size; //serve? parameter.Direction = dbParameter.Direction; parameter.Value = dbParameter.Value; cmd.Parameters.Add(parameter); } } cmd.CommandType = CommandType.StoredProcedure; #region DataReader SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.HasRows) { dt.Load(rdr); } #endregion } catch (Exception ex) { errorMessage = String.Format(CultureInfo.CurrentCulture, "Exception Type: {0}, Message: {1}{2}", ex.GetType(), ex.Message, ex.InnerException == null ? String.Empty : String.Format(CultureInfo.CurrentCulture, " InnerException Type: {0}, Message: {1}", ex.InnerException.GetType(), ex.InnerException.Message)); dt = null; } CloseConnection(); return errorMessage; }
public string ExecuteProcedure(SqlCommandObject SQLobj, out DataTable dt) { dt = new DataTable(); try { OpenConnection(); SqlCommand cmd = new SqlCommand(SQLobj.SPName, con); if (SQLobj.SPParams != null) { foreach (DbParameter dbParameter in SQLobj.SPParams) { SqlParameter parameter = new SqlParameter(); parameter.ParameterName = "@" + dbParameter.ParameterName; parameter.DbType = dbParameter.DbType; //parameter.Size = dbParameter.Size; //serve? parameter.Direction = dbParameter.Direction; parameter.Value = dbParameter.Value; cmd.Parameters.Add(parameter); } } cmd.CommandType = CommandType.StoredProcedure; #region DataReader SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.HasRows) { dt.Load(rdr); } #endregion } catch (Exception ex) { errorMessage = String.Format(CultureInfo.CurrentCulture, "Exception Type: {0}, Message: {1}{2}", ex.GetType(), ex.Message, ex.InnerException == null ? String.Empty : String.Format(CultureInfo.CurrentCulture, " InnerException Type: {0}, Message: {1}", ex.InnerException.GetType(), ex.InnerException.Message)); dt = null; } CloseConnection(); return(errorMessage); }