예제 #1
0
        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);
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
 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);
 }
예제 #4
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);
        }
예제 #5
0
        /// <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);
        }
예제 #6
0
        /// <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);
        }