Example #1
0
 private object getOutputParameters(SqlCommand Command, Procedure Structure)
 {
     object _return = null;
     foreach (ProcedureParameter _ProcedureParameter in Structure) {
         if (_ProcedureParameter.Direction != ParameterDirection.Input) {
             _ProcedureParameter.Value = Command.Parameters[_ProcedureParameter.Name].Value;
             if (_ProcedureParameter.Direction == ParameterDirection.ReturnValue) {
                 _return = _ProcedureParameter.Value;
             }
         }
     }
     return _return;
 }
Example #2
0
 public object InvokeProcedureResult(Procedure inProcedure)
 {
     SqlCommand _command;
     if (string.IsNullOrEmpty(inProcedure.Command)) {
         _command = new SqlCommand(inProcedure.Name, _con);
         _command.CommandType = CommandType.StoredProcedure;
     } else {
         _command = new SqlCommand(inProcedure.Command, _con);
         _command.CommandType = CommandType.Text;
     }
     _command.CommandTimeout = _dbi.Timeout;
     if (inProcedure.HasParameter) {
         AddParameters(_command, inProcedure);
     }
     object _result = null;
     if(!inProcedure.HasReturnParameter)
         _command.Parameters.AddWithValue("xy_Procedure_Return", _result).Direction = ParameterDirection.ReturnValue;
     this.Open();
     try {
         if (_trans != null) _command.Transaction = _trans;
         _command.ExecuteNonQuery();
     } catch (Exception ex) {
         ErrorString = ex.Message;
         throw ex;
     } finally {
         if (_trans == null) _con.Close();
     }
     if (inProcedure.HasReturnParameter) {
         _result = getOutputParameters(_command, inProcedure);
     } else {
         _result = _command.Parameters["xy_Procedure_Return"].Value;
     }
     if (_result != null) {
         return _result;
     } else {
         throw new Exception("要求返回数值时返回为空");
     }
 }
Example #3
0
 private void AddParameters(SqlCommand Command, Procedure Structure)
 {
     foreach (ProcedureParameter _ProcedureParameter in Structure) {
         System.Data.SqlClient.SqlParameter _temp = new SqlParameter(_ProcedureParameter.Name, _ProcedureParameter.Type);
         _temp.Value = _ProcedureParameter.Value;
         _temp.Direction = _ProcedureParameter.Direction;
         Command.Parameters.Add(_temp);
     }
 }
Example #4
0
 public DataSet InvokeProcedureFillSet(Procedure inProcedure)
 {
     int? result;
     return InvokeProcedureFillSet(inProcedure, out result);
 }
Example #5
0
 public DataSet InvokeProcedureFillSet(Procedure inProcedure, out int? result)
 {
     SqlCommand _command;
     if (string.IsNullOrEmpty(inProcedure.Command)) {
         _command = new SqlCommand(inProcedure.Name, _con);
         _command.CommandType = CommandType.StoredProcedure;
     } else {
         _command = new SqlCommand(inProcedure.Command, _con);
         _command.CommandType = CommandType.Text;
     }
     _command.CommandTimeout = _dbi.Timeout;
     if (inProcedure.HasParameter) {
         AddParameters(_command, inProcedure);
     }
     DataSet _dataSet = new DataSet();
     SqlDataAdapter _dataAdapter = new SqlDataAdapter(_command);
     try {
         if (_trans != null) _command.Transaction = _trans;
         _dataAdapter.Fill(_dataSet);
     } catch (Exception ex) {
         ErrorString = "在存储过程中发生了错误:" + ex.Message;
         throw ex;
     }
     result = (int?)getOutputParameters(_command, inProcedure);
     return _dataSet;
 }
Example #6
0
 //public int InvokeCommand(string Command) {
 //    SqlCommand _command = new SqlCommand(Command, _con);
 //    _command.CommandType = CommandType.Text;
 //    this.Open();
 //    int editRow = 0;
 //    try {
 //        if (_trans != null) _command.Transaction = _trans;
 //        editRow = _command.ExecuteNonQuery();
 //    } catch (Exception ex) {
 //        ErrorString = ex.Message;
 //        throw ex;
 //    } finally {
 //        if (_trans == null) _con.Close();
 //    }
 //    return editRow;
 //}
 //public DataTable InvokeCommandFill(string Command) {
 //    SqlCommand _command = new SqlCommand(Command, _con);
 //    _command.CommandType = CommandType.Text;
 //    DataSet _dataSet = new DataSet();
 //    SqlDataAdapter _dataAdapter = new SqlDataAdapter(_command);
 //    try {
 //        if (_trans != null) _command.Transaction = _trans;
 //        _dataAdapter.Fill(_dataSet);
 //    } catch (Exception ex) {
 //        ErrorString = "在存储过程中发生了错误:" + ex.Message;
 //        throw ex;
 //    }
 //    if (_dataSet.Tables.Count > 0) {
 //        return _dataSet.Tables[0];
 //    } else {
 //        return new DataTable();
 //    }
 //}
 public int InvokeProcedure(Procedure inProcedure)
 {
     SqlCommand _command;
     if (string.IsNullOrEmpty(inProcedure.Command)) {
         _command = new SqlCommand(inProcedure.Name, _con);
         _command.CommandType = CommandType.StoredProcedure;
     } else {
         _command = new SqlCommand(inProcedure.Command, _con);
         _command.CommandType = CommandType.Text;
     }
     _command.CommandTimeout = _dbi.Timeout;
     if (inProcedure.HasParameter) {
         AddParameters(_command, inProcedure);
     }
     this.Open();
     int editRow = 0;
     try {
         if (_trans != null) _command.Transaction = _trans;
         editRow = _command.ExecuteNonQuery();
     } catch (Exception ex) {
         ErrorString = ex.Message;
         throw ex;
     } finally {
         if (_trans == null) _con.Close();
     }
     getOutputParameters(_command, inProcedure);
     return editRow;
 }
Example #7
0
 public DataTable InvokeProcedureFill(Procedure inProcedure)
 {
     int? result;
     return InvokeProcedureFill(inProcedure,out result);
 }
Example #8
0
 /// <summary>
 /// 执行存储过程,并填充一个DataSet对象
 /// </summary>
 /// <param name="procedureName">存储过程名</param>
 /// <param name="Structure">参数结构</param>
 /// <returns>DataSet对象</returns>
 public System.Data.DataSet InvokeProcedureFillSet(Procedure Structure)
 {
     return _db.InvokeProcedureFillSet(Structure);
 }
Example #9
0
 /// <summary>
 /// 执行存储过程,并返回存储过程返回的数值
 /// </summary>
 /// <param name="procedureName">存储过程名</param>
 /// <param name="Structure">参数结构</param>
 /// <returns>存储过程返回的值</returns>
 public object InvokeProcedureResult(Procedure Structure)
 {
     return _db.InvokeProcedureResult(Structure);
 }
Example #10
0
 /// <summary>
 /// 执行存储过程,并填充一个DataTable对象
 /// </summary>
 /// <param name="procedureName">存储过程名</param>
 /// <param name="Structure">参数结构</param>
 /// <returns>DataSet对象</returns>
 public System.Data.DataTable InvokeProcedureFill(Procedure Structure)
 {
     return _db.InvokeProcedureFill(Structure);
 }
Example #11
0
 /// <summary>
 /// 执行存储过程,并返回受影响的行数
 /// </summary>
 /// <param name="ProcedureName">存储过程名</param>
 /// <param name="Structure">参数结构</param>
 /// <returns>受影响的行数</returns>
 public int InvokeProcedure(Procedure Structure)
 {
     return _db.InvokeProcedure(Structure);
 }
Example #12
0
 private void AddParameters(MySqlCommand Command, Procedure Structure)
 {
     foreach (ProcedureParameter _ProcedureParameter in Structure) {
         MySqlParameter _temp = new MySqlParameter(_ProcedureParameter.Name, GetMySqlDbType(_ProcedureParameter.Type));
         _temp.Value = _ProcedureParameter.Value;
         _temp.Direction = _ProcedureParameter.Direction;
         Command.Parameters.Add(_temp);
     }
 }
Example #13
0
 public Procedure Clone()
 {
     Procedure _temp = new Procedure() {
         _name = _name,
         _defaultDB = _defaultDB,
         _command = _command,
         _hasReturn = _hasReturn,
         BeforeInvoke = BeforeInvoke,
         AfterInvoke = AfterInvoke
     };
     for (int i = 0; i < _value.Count; i++) {
         _temp._value.Add(_value[i].Clone());
     }
     return _temp;
 }
Example #14
0
        public DataTable InvokeProcedureFill(Procedure inProcedure)
        {
            int?result;

            return(InvokeProcedureFill(inProcedure, out result));
        }