Exemple #1
0
        internal bool AreParameterBindingsInvalid(OleDbParameterCollection collection)
        {
            Debug.Assert(null != collection, "null parameter collection");
            Debug.Assert(null != _parameters, "null parameters");

            ColumnBinding[] columnBindings = this.ColumnBindings();
            if (!ForceRebind && ((collection.ChangeID == _collectionChangeID) && (_parameters.Length == collection.Count)))
            {
                for (int i = 0; i < columnBindings.Length; ++i)
                {
                    ColumnBinding binding = columnBindings[i];

                    Debug.Assert(null != binding, "null column binding");
                    Debug.Assert(binding.Parameter() == _parameters[i], "parameter mismatch");
                    if (binding.IsParameterBindingInvalid(collection[i]))
                    {
                        //Debug.WriteLine("ParameterBindingsInvalid");
                        return(true);
                    }
                }
                //Debug.WriteLine("ParameterBindingsValid");
                return(false); // collection and cached values are the same
            }
            //Debug.WriteLine("ParameterBindingsInvalid");
            return(true);
        }
Exemple #2
0
        private void PrepareCommandText(int expectedExecutionCount)
        {
            OleDbParameterCollection parameters = _parameters;

            if (null != parameters)
            {
                foreach (OleDbParameter parameter in parameters)
                {
                    if (parameter.IsParameterComputed())
                    {
                        // @devnote: use IsParameterComputed which is called in the normal case
                        // only to call Prepare to throw the specialized error message
                        // reducing the overall number of methods to actually jit
                        parameter.Prepare(this);
                    }
                }
            }
            UnsafeNativeMethods.ICommandPrepare icommandPrepare = ICommandPrepare();
            if (null != icommandPrepare)
            {
                OleDbHResult hr;
                hr = icommandPrepare.Prepare(expectedExecutionCount);

                ProcessResults(hr);
            }
            // don't recompute bindings on prepared statements
            _isPrepared = true;
        }
Exemple #3
0
        private void CreateAccessor()
        {
            Debug.Assert(System.Data.CommandType.Text == CommandType || System.Data.CommandType.StoredProcedure == CommandType, "CreateAccessor: incorrect CommandType");
            Debug.Assert(null == _dbBindings, "CreateAccessor: already has dbBindings");
            Debug.Assert(HasParameters(), "CreateAccessor: unexpected, no parameter collection");

            // do this first in-case the command doesn't support parameters
            UnsafeNativeMethods.ICommandWithParameters commandWithParameters = ICommandWithParameters();

            OleDbParameterCollection collection = _parameters !;

            OleDbParameter[] parameters = new OleDbParameter[collection.Count];
            collection.CopyTo(parameters, 0);

            // _dbBindings is used as a switch during ExecuteCommand, so don't set it until everything okay
            Bindings bindings = new Bindings(parameters, collection.ChangeID);

            for (int i = 0; i < parameters.Length; ++i)
            {
                bindings.ForceRebind |= parameters[i].BindParameter(i, bindings);
            }

            bindings.AllocateForAccessor(null, 0, 0);

            ApplyParameterBindings(commandWithParameters, bindings.BindInfo !);

            UnsafeNativeMethods.IAccessor iaccessor = IAccessor();
            OleDbHResult hr = bindings.CreateAccessor(iaccessor, ODB.DBACCESSOR_PARAMETERDATA);

            if (hr < 0)
            {
                ProcessResults(hr);
            }
            _dbBindings = bindings;
        }
Exemple #4
0
		public OleDbCommand ()
		{
			timeout = DEFAULT_COMMAND_TIMEOUT;
			commandType = CommandType.Text;
			parameters = new OleDbParameterCollection ();
			behavior = CommandBehavior.Default;
			gdaCommand = IntPtr.Zero;
			designTimeVisible = true;
			this.updatedRowSource = UpdateRowSource.Both;
		}
Exemple #5
0
 public OleDbCommand()
 {
     timeout               = DEFAULT_COMMAND_TIMEOUT;
     commandType           = CommandType.Text;
     parameters            = new OleDbParameterCollection();
     behavior              = CommandBehavior.Default;
     gdaCommand            = IntPtr.Zero;
     designTimeVisible     = true;
     this.updatedRowSource = UpdateRowSource.Both;
 }
Exemple #6
0
        private void addParameters(OleDbParameterCollection parameters)
        {
            parameters.Add("@fullname", OleDbType.VarChar, 50, "fullname");
            parameters.Add("@username", OleDbType.VarChar, 24, "_username");
            parameters.Add("@password", OleDbType.VarChar, 24, "_password");

            parameters.Add("@admin", OleDbType.Boolean, 2, "admin");
            parameters.Add("@blocked", OleDbType.Boolean, 2, "blocked");
            parameters.Add("@id", OleDbType.Integer, 4, "id");
        }
Exemple #7
0
        /// <include file='doc\OleDbCommandBuilder.uex' path='docs/doc[@for="OleDbCommandBuilder.DeriveParameters"]/*' />
        static public void DeriveParameters(OleDbCommand command)   // MDAC 65927
        {
            OleDbConnection.OleDbPermission.Demand();

            if (null == command)
            {
                throw ADP.ArgumentNull("command");
            }
            switch (command.CommandType)
            {
            case System.Data.CommandType.Text:
                throw ADP.DeriveParametersNotSupported(command);

            case System.Data.CommandType.StoredProcedure:
                break;

            case System.Data.CommandType.TableDirect:
                // CommandType.TableDirect - do nothing, parameters are not supported
                throw ADP.DeriveParametersNotSupported(command);

            default:
                throw ADP.InvalidCommandType(command.CommandType);
            }
            if (ADP.IsEmpty(command.CommandText))
            {
                throw ADP.CommandTextRequired(ADP.DeriveParameters);
            }
            OleDbConnection connection = command.Connection;

            if (null == connection)
            {
                throw ADP.ConnectionRequired(ADP.DeriveParameters);
            }
            ConnectionState state = connection.State;

            if (ConnectionState.Open != state)
            {
                throw ADP.OpenConnectionRequired(ADP.DeriveParameters, state);
            }
            OleDbParameter[] list = DeriveParametersFromStoredProcedure(connection, command);

            OleDbParameterCollection parameters = command.Parameters;

            parameters.Clear();

            int count = list.Length;

            if (0 < count)
            {
                for (int i = 0; i < list.Length; ++i)
                {
                    parameters.Add(list[i]);
                }
            }
        }
Exemple #8
0
 void SetParameterValue(OleDbParameterCollection Params, object value, OleDbType type)
 {
     if (value != null)
     {
         Params.Add("?", type).Value = value;
     }
     else
     {
         Params.AddWithValue("?", DBNull.Value);
     }
 }
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         this._changeID++;
         this.ResetConnection();
         this._transaction = null;
         this._parameters  = null;
         this.CommandText  = null;
     }
     base.Dispose(disposing);
 }
		public OleDbCommand ()
	        {
			commandText = String.Empty;
			timeout = 30; // default timeout per .NET
			commandType = CommandType.Text;
			connection = null;
			parameters = new OleDbParameterCollection ();
			transaction = null;
			designTimeVisible = false;
			dataReader = null;
			behavior = CommandBehavior.Default;
			gdaCommand = IntPtr.Zero;
		}
        private OleDbCommand(OleDbCommand from) : this()
        {
            this.CommandText       = from.CommandText;
            this.CommandTimeout    = from.CommandTimeout;
            this.CommandType       = from.CommandType;
            this.Connection        = from.Connection;
            this.DesignTimeVisible = from.DesignTimeVisible;
            this.UpdatedRowSource  = from.UpdatedRowSource;
            this.Transaction       = from.Transaction;
            OleDbParameterCollection parameters = this.Parameters;

            foreach (object obj2 in from.Parameters)
            {
                parameters.Add((obj2 is ICloneable) ? (obj2 as ICloneable).Clone() : obj2);
            }
        }
Exemple #12
0
        private OleDbCommand(OleDbCommand from) : this()
        { // Clone
            CommandText       = from.CommandText;
            CommandTimeout    = from.CommandTimeout;
            CommandType       = from.CommandType;
            Connection        = from.Connection;
            DesignTimeVisible = from.DesignTimeVisible;
            UpdatedRowSource  = from.UpdatedRowSource;
            Transaction       = from.Transaction;

            OleDbParameterCollection parameters = Parameters;

            foreach (object parameter in from.Parameters)
            {
                parameters.Add(parameter is ICloneable cloneableParameter ? cloneableParameter.Clone() : parameter);
            }
        }
 internal bool AreParameterBindingsInvalid(OleDbParameterCollection collection)
 {
     ColumnBinding[] bindingArray = this.ColumnBindings();
     if ((this.ForceRebind || (collection.ChangeID != this._collectionChangeID)) || (this._parameters.Length != collection.Count))
     {
         return(true);
     }
     for (int i = 0; i < bindingArray.Length; i++)
     {
         ColumnBinding binding = bindingArray[i];
         if (binding.IsParameterBindingInvalid(collection[i]))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #14
0
        public static void DeriveParameters(OleDbCommand command)
        {
            OleDbConnection.ExecutePermission.Demand();
            if (command == null)
            {
                throw ADP.ArgumentNull("command");
            }
            CommandType commandType = command.CommandType;

            if (commandType == CommandType.Text)
            {
                throw ADP.DeriveParametersNotSupported(command);
            }
            if (commandType != CommandType.StoredProcedure)
            {
                if (commandType == CommandType.TableDirect)
                {
                    throw ADP.DeriveParametersNotSupported(command);
                }
                throw ADP.InvalidCommandType(command.CommandType);
            }
            if (ADP.IsEmpty(command.CommandText))
            {
                throw ADP.CommandTextRequired("DeriveParameters");
            }
            OleDbConnection connection = command.Connection;

            if (connection == null)
            {
                throw ADP.ConnectionRequired("DeriveParameters");
            }
            ConnectionState state = connection.State;

            if (ConnectionState.Open != state)
            {
                throw ADP.OpenConnectionRequired("DeriveParameters", state);
            }
            OleDbParameter[]         parameterArray = DeriveParametersFromStoredProcedure(connection, command);
            OleDbParameterCollection parameters     = command.Parameters;

            parameters.Clear();
            for (int i = 0; i < parameterArray.Length; i++)
            {
                parameters.Add(parameterArray[i]);
            }
        }
Exemple #15
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            { // release mananged objects
              // the DataReader takes ownership of the parameter Bindings
              // this way they don't get destroyed when user calls OleDbCommand.Dispose
              // when there is an open DataReader

                unchecked
                { _changeID++; }

                // in V1.0, V1.1 the Connection,Parameters,CommandText,Transaction where reset
                ResetConnection();
                _transaction = null;
                _parameters  = null;
                CommandText  = null;
            }
            // release unmanaged objects
            base.Dispose(disposing); // notify base classes
        }
Exemple #16
0
        /// <summary>
        /// 将 <see cref="SqlParameterCollection"/> 对象中的参数加入到 <see cref="OleDbParameterCollection"/> 对象中。
        /// </summary>
        /// <param name="sqlParameterCollection"><see cref="SqlParameterCollection"/> 对象</param>
        /// <param name="oleDbParameterCollection"><see cref="OleDbParameterCollection"/> 对象</param>
        private void AddDbParameter(SqlParameterCollection sqlParameterCollection, System.Data.OleDb.OleDbParameterCollection oleDbParameterCollection)
        {
            if (sqlParameterCollection == null || oleDbParameterCollection == null)
            {
                return;
            }

            OleDbParameter[] clonedParameters = new OleDbParameter[sqlParameterCollection.Count];
            for (int i = 0, j = sqlParameterCollection.Count; i < j; i++)
            {
                OleDbParameter p = (OleDbParameter)((ICloneable)sqlParameterCollection[i]).Clone();

                // 检查未分配值的输入参数,将其分配以DBNull.Value.
                if ((p.Direction == ParameterDirection.InputOutput || p.Direction == ParameterDirection.Input) && (p.Value == null))
                {
                    p.Value = DBNull.Value;
                }
                clonedParameters[i] = p;
            }
            oleDbParameterCollection.AddRange(clonedParameters);
        }
        private void CreateAccessor()
        {
            System.Data.Common.UnsafeNativeMethods.ICommandWithParameters commandWithParameters = this.ICommandWithParameters();
            OleDbParameterCollection parameters = this._parameters;

            OleDbParameter[] array = new OleDbParameter[parameters.Count];
            parameters.CopyTo(array, 0);
            Bindings bindings = new Bindings(array, parameters.ChangeID);

            for (int i = 0; i < array.Length; i++)
            {
                bindings.ForceRebind |= array[i].BindParameter(i, bindings);
            }
            bindings.AllocateForAccessor(null, 0, 0);
            this.ApplyParameterBindings(commandWithParameters, bindings.BindInfo);
            System.Data.Common.UnsafeNativeMethods.IAccessor iaccessor = this.IAccessor();
            OleDbHResult hr = bindings.CreateAccessor(iaccessor, 4);

            if (hr < OleDbHResult.S_OK)
            {
                this.ProcessResults(hr);
            }
            this._dbBindings = bindings;
        }
        private void PrepareCommandText(int expectedExecutionCount)
        {
            OleDbParameterCollection parameters = this._parameters;

            if (parameters != null)
            {
                foreach (OleDbParameter parameter in parameters)
                {
                    if (parameter.IsParameterComputed())
                    {
                        parameter.Prepare(this);
                    }
                }
            }
            System.Data.Common.UnsafeNativeMethods.ICommandPrepare prepare = this.ICommandPrepare();
            if (prepare != null)
            {
                Bid.Trace("<oledb.ICommandPrepare.Prepare|API|OLEDB> %d#, expectedExecutionCount=%d\n", this.ObjectID, expectedExecutionCount);
                OleDbHResult result = prepare.Prepare(expectedExecutionCount);
                Bid.Trace("<oledb.ICommandPrepare.Prepare|API|OLEDB|RET> %08X{HRESULT}\n", result);
                this.ProcessResults(result);
            }
            this._isPrepared = true;
        }
Exemple #19
0
 /// <summary>
 /// 增加参数
 /// </summary>
 /// <param name="cmd">cmd对象</param>
 /// <param name="dbParameterCollection">参数集合</param>
 public void AddParameterCollection(OleDbCommand cmd, OleDbParameterCollection dbParameterCollection)
 {
     foreach (OleDbParameter dbParameter in dbParameterCollection)
     {
         cmd.Parameters.Add(dbParameter);
     }
 }
 internal bool AreParameterBindingsInvalid(OleDbParameterCollection collection)
 {
     ColumnBinding[] bindingArray = this.ColumnBindings();
     if ((this.ForceRebind || (collection.ChangeID != this._collectionChangeID)) || (this._parameters.Length != collection.Count))
     {
         return true;
     }
     for (int i = 0; i < bindingArray.Length; i++)
     {
         ColumnBinding binding = bindingArray[i];
         if (binding.IsParameterBindingInvalid(collection[i]))
         {
             return true;
         }
     }
     return false;
 }
Exemple #21
0
        internal bool AreParameterBindingsInvalid(OleDbParameterCollection collection) {
            Debug.Assert(null != collection, "null parameter collection");
            Debug.Assert(null != _parameters, "null parameters");

            ColumnBinding[] columnBindings = this.ColumnBindings();
            if (!ForceRebind && ((collection.ChangeID == _collectionChangeID) && (_parameters.Length == collection.Count))) {
                for(int i = 0; i < columnBindings.Length; ++i) {
                    ColumnBinding binding = columnBindings[i];

                    Debug.Assert(null != binding, "null column binding");
                    Debug.Assert(binding.Parameter() == _parameters[i], "parameter mismatch");
                    if (binding.IsParameterBindingInvalid(collection[i])) {
                        //Debug.WriteLine("ParameterBindingsInvalid");
                        return true;
                    }
                }
                //Debug.WriteLine("ParameterBindingsValid");
                return false; // collection and cached values are the same
            }
            //Debug.WriteLine("ParameterBindingsInvalid");
            return true;
        }
        private bool HasParameters()
        {
            OleDbParameterCollection parameters = this._parameters;

            return((parameters != null) && (0 < parameters.Count));
        }
Exemple #23
0
        private bool HasParameters()
        {
            OleDbParameterCollection value = _parameters;

            return((null != value) && (0 < value.Count));
        }
Exemple #24
0
 public static void Entry_AddParameters(OleDbParameterCollection parameters)
 {
     parameters.Add("@kg_doc", OleDbType.Double, 8, "kg_doc");
     parameters.Add("@kg_rcvd", OleDbType.Double, 8, "kg_rcvd");
     parameters.Add("@m3", OleDbType.Double, 8, "m3");
     parameters.Add("@cll_doc", OleDbType.Integer, 4, "cll_doc");
     parameters.Add("@cll_rcvd", OleDbType.Integer, 4, "cll_rcvd");
     addCommonParameters(parameters);
 }
        override protected void Dispose(bool disposing) { // MDAC 65459
            if (disposing) { // release mananged objects
                // the DataReader takes ownership of the parameter Bindings
                // this way they don't get destroyed when user calls OleDbCommand.Dispose
                // when there is an open DataReader

                unchecked { _changeID++; }

                // in V1.0, V1.1 the Connection,Parameters,CommandText,Transaction where reset
                ResetConnection();
                _transaction = null;
                _parameters = null;
                CommandText = null;
            }
            // release unmanaged objects
            base.Dispose(disposing); // notify base classes
        }
Exemple #26
0
 //todo: remove, use Views from MainForm datagrid and update using dataTable
 private void addParemeters(OleDbParameterCollection parameters)
 {
     parameters.Add("@stock_id", OleDbType.Integer).Value = stockId;
     parameters.Add("@invoice_number", OleDbType.VarWChar).Value = tbInvoiceNumber.Text;
     parameters.Add("@hasTax", OleDbType.Boolean).Value = cbTax.Checked;
     parameters.Add("@invoice_date", OleDbType.DBTimeStamp).Value = DateTime.Parse(dtpInvoice.Value.ToString());
     parameters.Add("@due_date", OleDbType.DBTimeStamp).Value = DateTime.Parse(dtpInvoiceDue.Value.ToString());
     parameters.Add("@ccs_number", OleDbType.VarWChar).Value = (ccsNumber == null) ? "" : ccsNumber;
     parameters.Add("@receiver", OleDbType.VarWChar).Value = tbReceiver.Text;
     parameters.Add("@summary", OleDbType.VarWChar).Value = tbSummary.Text;
     parameters.Add("@company_info", OleDbType.VarWChar).Value = tbCompanyInfo.Text;
     parameters.Add("@address", OleDbType.VarWChar).Value = tbAddress.Text;
     parameters.Add("@bank_details", OleDbType.VarWChar).Value = tbBankDetails.Text;
     parameters.Add("@cll_doc", OleDbType.Integer).Value = cll;
     parameters.Add("@kg_doc", OleDbType.Double).Value = kg;
     parameters.Add("@m3", OleDbType.Double).Value = m3;
     parameters.Add("@attached", OleDbType.VarWChar).Value = item.ItemArray[IndexOf("attached")].ToString();
     MainWindow.DataGridView_Deserialize(dataGridView, parameters);
 }
Exemple #27
0
        public static void DataGridView_Deserialize(DataGridView dataGridView, OleDbParameterCollection parameters)
        {
            Object[] cellsInColumns = new Object[dataGridView.Columns.Count];

            for (var i = 0; i < cellsInColumns.Length; i++)
            {
                cellsInColumns[i] = "";
            }

            for (int i = 0; i < dataGridView.Rows.Count - 1; i++)
            {
                DataGridViewRow row = dataGridView.Rows[i];
                foreach (DataGridViewCell cell in row.Cells)
                {
                    cellsInColumns[cell.ColumnIndex] += "|" + ((cell.Value != null) ? cell.Value.ToString() : "");
                }
            }

            for (var i = 0; i < cellsInColumns.Length; i++)
            {
                parameters.Add("@" + dataGridView.Columns[i].Name.ToLower(), OleDbType.VarWChar).Value = (cellsInColumns[i].ToString().Length > 0) ? cellsInColumns[i].ToString().Substring(1) : "";
            }
        }
Exemple #28
0
        private static void addCommonParameters(OleDbParameterCollection parameters)
        {
            parameters.Add("@booking_number", OleDbType.Integer, 4, "booking_number");
            parameters.Add("@arrival", OleDbType.DBTimeStamp, 4, "arrival");
            parameters.Add("@status", OleDbType.VarWChar, 2, "status");
            parameters.Add("@consignor", OleDbType.VarWChar, 50, "consignor");
            parameters.Add("@consignee", OleDbType.VarWChar, 50, "consignee");
            parameters.Add("@description", OleDbType.VarWChar, 500, "description");
            parameters.Add("@ccs_number", OleDbType.VarWChar, 11, "ccs_number");
            parameters.Add("@damage", OleDbType.VarWChar, 50, "damage");
            parameters.Add("@wh_number", OleDbType.VarWChar, 50, "wh_number");
            parameters.Add("@wh_pl", OleDbType.VarWChar, 50, "wh_pl");
            parameters.Add("@manager", OleDbType.VarWChar, 50, "manager");
            parameters.Add("@documents", OleDbType.VarWChar, 100, "documents");
            parameters.Add("@situation", OleDbType.VarWChar, 100, "situation");
            parameters.Add("@codes", OleDbType.VarWChar, 500, "codes");
            parameters.Add("@comments", OleDbType.VarWChar, 500, "comments");
            parameters.Add("@container", OleDbType.VarWChar, 255, "container");
            parameters.Add("@attached", OleDbType.VarWChar, 255, "attached");

            parameters.Add("@id", OleDbType.Integer, 4, "id");
        }
		/// <summary>
		/// Builds an OleDbParametersCollection for an INSERT command, according to the DbTypeParameters in this collection.
		/// </summary>
		/// <param name="a_oParams">The OleDbParameterCollection to be filled.</param>
		private void AddInsertCommandParameters(OleDbParameterCollection a_oParams)
		{
			foreach (DbTypeParameter l_oCurrent in this)
			{
				a_oParams.Add(l_oCurrent.ParameterName, l_oCurrent.Value);
			}
		}
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         this._changeID++;
         this.ResetConnection();
         this._transaction = null;
         this._parameters = null;
         this.CommandText = null;
     }
     base.Dispose(disposing);
 }