/// <summary> /// Executes a command intended to return a single value. /// </summary> /// /// <param name="CommandType"> /// The type of command to execute. /// </param> /// /// <param name="CommandText"> /// The command text for the command. /// </param> /// /// <returns> /// The query's returned value. /// </returns> /// public T ExecuteScalar <T>(CommandType CommandType, string CommandText) { T returnValue = default(T); using (this.Connection = DBManagerFactory.GetConnection(this.ProviderType)) { this.Open(); this.Command = DBManagerFactory.GetCommand(this.ProviderType); this.PrepareCommand(this.Command, this.Connection, this.Transaction, CommandType, CommandText, this.Parameters); try { returnValue = (T)Convert.ChangeType(this.Command.ExecuteScalar(), typeof(T)); } catch (InvalidCastException) { returnValue = default(T); } catch (FormatException) { returnValue = default(T); } catch (OverflowException) { returnValue = default(T); } this.Command.Parameters.Clear(); } return(returnValue); }
public void Open() { idbConnection = DBManagerFactory.GetConnection(this.providerType); string constr = string.Empty; string orginal = ConnectionString; string[] conn = ConnectionString.Split(';'); for (int i = 0; i < conn.Length; i++) { if (conn[i].Contains("Password")) { string[] Pass = conn[i].ToString().Split('='); { conn[i] = ("Password="******"==")).ToString();; } } constr = constr + ";" + conn[i].ToString(); } ConnectionString = constr.Remove(0, 1); idbConnection.ConnectionString = this.ConnectionString; if (idbConnection.State != ConnectionState.Open) { idbConnection.Open(); } ConnectionString = orginal; this.idbCommand = DBManagerFactory.GetCommand(this.ProviderType); }
/// <summary> /// Starts the transaction. A transaction is created if one was not already. /// </summary> /// public void BeginTransaction() { if (this.Transaction == null) { this.Transaction = DBManagerFactory.GetTransaction(ProviderType); } this.Command.Transaction = this.Transaction; }
public object ExecuteScalar(CommandType commandType, string commandText) { this.idbCommand = DBManagerFactory.GetCommand(this.ProviderType); PrepareCommand(idbCommand, this.Connection, this.Transaction, commandType, commandText, this.Parameters); object returnValue = idbCommand.ExecuteScalar(); idbCommand.Parameters.Clear(); return(returnValue); }
public IDataReader ExecuteReader(CommandType commandType, string commandText) { this.idbCommand = DBManagerFactory.GetCommand(this.ProviderType); idbCommand.Connection = this.Connection; PrepareCommand(idbCommand, this.Connection, this.Transaction, commandType, commandText, this.Parameters); this.DataReader = idbCommand.ExecuteReader(); idbCommand.Parameters.Clear(); return(this.DataReader); }
public void AddParameters(int index, string paramName, ParameterDirection OracleDbtype, OracleType dbtype) { if (index < idbParameters.Length) { idbParameters[index].ParameterName = paramName; idbParameters[index].Direction = OracleDbtype; DBManagerFactory.SetParameterType(this.providerType, dbtype, idbParameters[index]); } }
public void Open() { idbConnection = DBManagerFactory.GetConnection(this.providerType); idbConnection.ConnectionString = this.ConnectionString; if (idbConnection.State != ConnectionState.Open) { idbConnection.Open(); } this.idbCommand = DBManagerFactory.GetCommand(this.ProviderType); }
public void BeginTransaction() { if (this.idbTransaction == null) { idbTransaction = DBManagerFactory.GetTransaction(this.ProviderType, this.Connection); } this.idbCommand.Transaction = idbTransaction; }
public DataTable ExecuteDataTable(CommandType commandType, string commandText) { this.idbCommand = DBManagerFactory.GetCommand(this.ProviderType); PrepareCommand(idbCommand, this.Connection, this.Transaction, commandType, commandText, this.Parameters); IDbDataAdapter dataAdapter = DBManagerFactory.GetDataAdapter(this.ProviderType); dataAdapter.SelectCommand = idbCommand; DataSet dataSet = new DataSet(); dataAdapter.Fill(dataSet); idbCommand.Parameters.Clear(); return(dataSet.Tables[0]); }
/// <summary> /// Creates and then returns a data reader object. /// </summary> /// /// <remarks> /// It is up to the calling procedure to close the reader and dispose /// of the connection object. /// </remarks> /// /// <param name="CommandType"> /// The command type to use in creating the data reader. /// </param> /// /// <param name="CommandText"> /// The command text to use in creating the data reader. /// </param> /// /// <returns> /// The created data reader. /// </returns> /// public IDataReader ExecuteReader(CommandType CommandType, string CommandText) { this.Connection = DBManagerFactory.GetConnection(this.ProviderType); this.Open(); this.Command = DBManagerFactory.GetCommand(this.ProviderType); this.PrepareCommand(this.Command, this.Connection, this.Transaction, CommandType, CommandText, this.Parameters); IDataReader dataReader = this.Command.ExecuteReader(CommandBehavior.CloseConnection); this.Command.Parameters.Clear(); return(dataReader); }
/// <summary> /// Adds a new parameter to the list of parameters. /// </summary> /// /// <param name="ParamName"> /// The name of the parameter. /// </param> /// /// <param name="ObjValue"> /// The value to assign to the parameter. /// </param> /// public void AddParameter(string ParamName, object ObjValue) { if (this.Parameters == null) { this.Parameters = new List <IDataParameter>(); } IDataParameter newParameter = DBManagerFactory.GetParameter(this.ProviderType); newParameter.ParameterName = ParamName ?? throw new ArgumentNullException(nameof(ParamName)); newParameter.Value = ObjValue ?? DBNull.Value; this.Parameters.Add(newParameter); }
/// <summary> /// Executes a query that does not intend to return a query. /// </summary> /// /// <param name="CommandType"> /// The type of command to execute. /// </param> /// /// <param name="CommandText"> /// The command text for the command. /// </param> /// /// <returns> /// An integer value indicating success or failure of the command. /// </returns> /// public int ExecuteNonQuery(CommandType CommandType, string CommandText) { int returnValue = 0; using (this.Connection = DBManagerFactory.GetConnection(this.ProviderType)) { this.Open(); this.Command = DBManagerFactory.GetCommand(this.ProviderType); this.PrepareCommand(this.Command, this.Connection, this.Transaction, CommandType, CommandText, this.Parameters); returnValue = this.Command.ExecuteNonQuery(); this.Command.Parameters.Clear(); } return(returnValue); }
/// <summary> /// Executes a command and returns the result in a dataset. /// </summary> /// /// <param name="CommandType"> /// The type of command to execute. /// </param> /// /// <param name="CommandText"> /// The command text for the command. /// </param> /// /// <returns> /// A DataSet containing the results of the command. /// </returns> /// public DataSet ExecuteDataSet(CommandType CommandType, string CommandText) { var dataSet = new DataSet(); using (this.Connection = DBManagerFactory.GetConnection(this.ProviderType)) { this.Open(); this.Command = DBManagerFactory.GetCommand(this.ProviderType); this.PrepareCommand(this.Command, this.Connection, this.Transaction, CommandType, CommandText, this.Parameters); IDbDataAdapter dataAdapter = DBManagerFactory.GetDataAdapter(this.ProviderType); dataAdapter.SelectCommand = this.Command; dataAdapter.Fill(dataSet); this.Command.Parameters.Clear(); } return(dataSet); }
public DataSet ExecuteDataSet(CommandType commandType, string commandText) { try { this.idbCommand = DBManagerFactory.GetCommand(this.ProviderType); PrepareCommand(idbCommand, this.Connection, this.Transaction, commandType, commandText, this.Parameters); IDbDataAdapter dataAdapter = DBManagerFactory.GetDataAdapter (this.ProviderType); idbCommand.CommandTimeout = 999999; dataAdapter.SelectCommand = idbCommand; DataSet dataSet = new DataSet(); dataAdapter.Fill(dataSet); //if (commandText.Contains("firma_zrc")) //dataSet.Tables[0].Columns["zrc1"].AllowDBNull = false; //for (int i = 0; i < dataSet.Tables[0].Columns.Count; i++) //dataSet.Tables[0].Columns[i].AllowDBNull = false; //DataTable schema = GetSchema(commandText.Substring(0, commandText.IndexOf("_lst"))); //foreach(DataRow row in schema.Rows) //{ //if(row["IS_NULLABLE"].ToString()=="NO") //{ //dataSet.Tables[0].Columns[row["COLUMN_NAME"].ToString()].AllowDBNull = false; //} //} idbCommand.Parameters.Clear(); return(dataSet); } catch { throw; } }
public void CreateParameters(int paramsCount) { idbParameters = new IDbDataParameter[paramsCount]; idbParameters = DBManagerFactory.GetParameters(this.ProviderType, paramsCount); }