Esempio n. 1
0
        /// <summary>
        /// mehod to open  the connection to the data base
        /// </summary>
        public void Open()
        {
            try
            {
                // calling method from DBManagerFactory class to get the provider type connection object
                idbConnection = DBManagerFactory.GetConnection(this.providerType);

                // passing connection string
                idbConnection.ConnectionString = this.ConnectionString;

                if (idbConnection.State == ConnectionState.Open)
                {
                    idbConnection.Close();
                }

                // chek for open connection state
                if (idbConnection.State != ConnectionState.Open)
                {
                    idbConnection.Open();
                }
                // calling method from DBManagerFactory class to get the provider type command object
                this.idbCommand     = DBManagerFactory.GetCommand(this.ProviderType);
                this.idbTransaction = DBManagerFactory.GetTransaction(idbConnection, this.ProviderType);
            }
            catch (Exception ex)
            { throw ex; }
        }
Esempio n. 2
0
        /// <summary>
        /// method to execute the dataset property of the command object
        /// </summary>
        /// <param name="commandType"></param>
        /// <param name="commandText"></param>
        /// <returns></returns>
        public DataTable GetData(CommandType commandType, string commandText)
        {
            DataTable dt = null;

            try
            {
                // get the command object from the DBManagerFactory
                this.idbCommand = DBManagerFactory.GetCommand(this.ProviderType);

                // method to prepare the oommand object
                PrepareCommand(idbCommand, this.Connection, this.Transaction, commandType, commandText, this.Parameters);
                // get the data adapter from DBManagerFactory
                IDbDataAdapter dataAdapter = DBManagerFactory.GetDataAdapter(this.ProviderType);
                // assign the selected command property
                dataAdapter.SelectCommand = idbCommand;

                DataSet dataSet = new DataSet();
                // fill the dataset
                dataAdapter.Fill(dataSet);
                // clear the command parameters
                idbCommand.Parameters.Clear();
                dt = dataSet.Tables[0];
                dataSet.Dispose();
                return(dt);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 3
0
 /// <summary>
 /// method to add the parameters to the specified provider type command object
 /// </summary>
 /// <param name="paramsCount"></param>
 public void CreateParameters(int paramsCount)
 {
     try
     {
         idbParameters = new IDbDataParameter[paramsCount];
         // method to get the list of parametes added to the parameter object array
         idbParameters = DBManagerFactory.GetParameters(this.ProviderType, paramsCount);
     }
     catch (Exception ex)
     { throw ex; }
 }
Esempio n. 4
0
 /// <summary>
 /// method to begin the transaction
 /// </summary>
 public void BeginTransaction()
 {
     try
     {
         if (this.idbTransaction == null)
         {
             // calling method from DBManagerFactory to open the transaction of specific provider
             idbTransaction = DBManagerFactory.GetTransaction(this.idbConnection, this.ProviderType);
         }
         // assign the transaction to the command object
         this.idbCommand.Transaction = idbTransaction;
     }
     catch (Exception ex)
     { throw ex; }
 }
Esempio n. 5
0
        /// <summary>
        /// method to execute thte scalar property of the command object
        /// </summary>
        /// <param name="commandType"></param>
        /// <param name="commandText"></param>
        /// <returns></returns>
        public object ExecuteScalar(CommandType commandType, string commandText)
        {
            try
            {
                // get the command object for DBManagerFactory
                this.idbCommand = DBManagerFactory.GetCommand(this.ProviderType);

                // prepare the command object
                PrepareCommand(idbCommand, this.Connection, this.Transaction, commandType,
                               commandText, this.Parameters);

                // get the scalar return value to object
                object returnValue = idbCommand.ExecuteScalar();
                // clear the paerameters
                idbCommand.Parameters.Clear();
                return(returnValue);
            }
            catch (Exception ex)
            { throw ex; }
        }
Esempio n. 6
0
        /// <summary>
        /// method to execute the non query
        /// </summary>
        /// <param name="commandType"></param>
        /// <param name="commandText"></param>
        /// <returns></returns>
        public int ExecuteNonQuery(CommandType commandType, string commandText)
        {
            try
            {
                // get the command object from DBManagerFactory
                this.idbCommand = DBManagerFactory.GetCommand(this.ProviderType);

                // prepare the command object
                PrepareCommand(idbCommand, this.Connection, this.Transaction, commandType,
                               commandText, this.Parameters);
                // get the executed value
                int returnValue = idbCommand.ExecuteNonQuery();

                // clear the command parameters
                idbCommand.Parameters.Clear();
                return(returnValue);
            }
            catch (Exception ex)
            { throw ex; }
        }
Esempio n. 7
0
        /// <summary>
        /// method to execute the reader of the specific provider
        /// </summary>
        /// <param name="commandType"></param>
        /// <param name="commandText"></param>
        /// <returns></returns>
        public IDataReader ExecuteReader(CommandType commandType, string commandText)
        {
            try
            {
                // get the command object from DBManagerFactory by the provider type
                this.idbCommand = DBManagerFactory.GetCommand(this.ProviderType);
                // assingn the connection property to thcommand object
                idbCommand.Connection = this.Connection;

                // prepare the command object with the parameters
                PrepareCommand(idbCommand, this.Connection, this.Transaction,
                               commandType, commandText, this.Parameters);

                // assign the datareader
                this.DataReader = idbCommand.ExecuteReader();
                // clear the paramerts
                idbCommand.Parameters.Clear();
                return(this.DataReader);
            }
            catch (Exception ex)
            { throw ex; }
        }