public static IDbCommand GetCommand(string sql, CommandType cmdType, int timeout , DbParameter[] parameters, DataProvider provider) { IDbCommand command = GetCommand(provider); if (parameters != null) { for (int index = 0; index < parameters.Length; index++) { DbParameter parameter = parameters[index]; if (parameter == null) continue; IDbDataParameter param = GetParameter(parameter.Name , parameter.Direction , parameter.Value , parameter.DataType , parameter.SourceColumn , (short)parameter.Size, provider); command.Parameters.Add(param); } } command.CommandType = cmdType; command.CommandText = sql; command.CommandTimeout = timeout; return command; }
/// <summary> /// �����ݿ����Ӻ����� /// </summary> /// <param name="sql">SQL�ַ���</param> /// <param name="cmdType">��������</param> /// <param name="parameterArray">�������</param> /// <param name="command">���ص����ݿ�����</param> public IDbCommand PrepareAll(string sql, CommandType type, DbParameter[] parameters) { IDbCommand command = ProviderFactory.GetCommand(sql , type, this.m_timeOut, parameters, this.m_provider); if (this.IsInTransaction()) { command.Connection = this.m_connection; command.Transaction = this.m_transaction; } else { this.OpenConnnection(); command.Connection = this.m_connection; } return command; }
public object ExecuteScalar(string sql, CommandType cmdType, ref DbParameter[] parameters) { IDbCommand cmd = null; try { cmd = this.PrepareAll(sql, cmdType, parameters); return cmd.ExecuteScalar(); } catch (Exception ex) { this.GenericExceptionHandler(ex); return null; } finally { this.CloseConnnection(true); if (cmd != null) cmd.Dispose(); } }
public IDataReader ExecuteReader(string sql, CommandType cmdType, ref DbParameter[] parameters) { IDbCommand cmd = null; try { cmd = this.PrepareAll(sql, cmdType, parameters); this.m_dataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection); return this.m_dataReader; } catch (Exception ex) { this.GenericExceptionHandler(ex); return null; } finally { if (cmd != null) cmd.Dispose(); } }
public int ExecuteNonQuery(string sql, CommandType cmdType, ref DbParameter[] parameters) { IDbCommand cmd = null; try { cmd = this.PrepareAll(sql, cmdType, parameters); int nResult = cmd.ExecuteNonQuery(); int nCount = cmd.Parameters.Count; for (int index = 0; index < nCount; index++) { IDbDataParameter param = (IDbDataParameter)cmd.Parameters[index]; if (param.Direction == ParameterDirection.Output || param.Direction == ParameterDirection.InputOutput) { parameters[index].Value = param.Value; } } this.m_bNeedCommit = true; return nResult; } catch (Exception ex) { this.GenericExceptionHandler(ex); return -1; } finally { this.CloseConnnection(true); if (cmd != null) cmd.Dispose(); } }
public DataSet ExecuteDataSet(string sql, CommandType cmdType, ref DbParameter[] parameters) { IDbDataAdapter adapter = null; DataSet dataSet = new DataSet(); try { adapter = ProviderFactory.GetAdapter(this.m_provider); adapter.SelectCommand = this.PrepareAll(sql, cmdType, parameters); dataSet.Clear(); adapter.Fill(dataSet); return dataSet; } catch (Exception ex) { this.GenericExceptionHandler(ex); return null; } finally { this.CloseConnnection(true); if (adapter != null) { if (adapter.SelectCommand != null) adapter.SelectCommand.Dispose(); ((IDisposable)adapter).Dispose(); } } }
public object ExecuteScalar(string sql, CommandType cmdType, ref DbParameter[] parameters) { return this.CurrentContext.ExecuteScalar(sql, cmdType, ref parameters); }
public IDataReader ExecuteReader(string sql, CommandType cmdType, ref DbParameter[] parameters) { return this.CurrentContext.ExecuteReader(sql, cmdType, ref parameters); }
public int ExecuteNonQuery(string sql, CommandType cmdType, ref DbParameter[] parameters) { return this.CurrentContext.ExecuteNonQuery(sql, cmdType, ref parameters); }
public DataSet ExecuteDataSet(string sql, CommandType cmdType, ref DbParameter[] parameters) { return this.CurrentContext.ExecuteDataSet(sql, cmdType, ref parameters); }