Пример #1
0
        // If it's an Insert we fetch the @@Identity value and stuff it in the proper column
        protected void OnRowUpdated(object sender, OleDbRowUpdatedEventArgs e)
        {
            try
            {
                if (e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert)
                {
                    TransactionMgr txMgr = TransactionMgr.ThreadTransactionMgr();

                    OleDbCommand cmd = new OleDbCommand("SELECT @@IDENTITY");

                    // We make sure we enlist in the ongoing transaction, otherwise, we
                    // would most likely deadlock
                    txMgr.Enlist(cmd, this);
                    object o = cmd.ExecuteScalar();                     // Get the Identity Value
                    txMgr.DeEnlist(cmd, this);

                    if (o != null)
                    {
                        e.Row[this.GetAutoKeyColumn()] = o;
                        e.Row.AcceptChanges();
                    }
                }
            }
            catch {}
        }
Пример #2
0
        // If it's an Insert we fetch the @@Identity value and stuff it in the proper column
        protected void OnRowUpdated(object sender, MySqlRowUpdatedEventArgs e)
        {
            try
            {
                if (e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert)
                {
                    TransactionMgr txMgr = TransactionMgr.ThreadTransactionMgr();

                    string identityCol = this.GetAutoKeyColumns();

                    MySqlCommand cmd = new MySqlCommand();

                    cmd.CommandText = "SELECT LAST_INSERT_ID();";

                    // We make sure we enlist in the ongoing transaction, otherwise, we
                    // would most likely deadlock
                    txMgr.Enlist(cmd, this);
                    object o = cmd.ExecuteScalar();                     // Get the Identity Value
                    txMgr.DeEnlist(cmd, this);

                    if (o != null)
                    {
                        e.Row[identityCol] = o;
                    }

                    e.Row.AcceptChanges();
                }
            }
            catch {}
        }
Пример #3
0
        // If it's an Insert we fetch the @@Identity value and stuff it in the proper column
        protected void OnRowUpdated(object sender, RowUpdatedEventArgs e)
        {
            try
            {
                if (e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert)
                {
                    TransactionMgr txMgr = TransactionMgr.ThreadTransactionMgr();

                    string[] identityCols = this.GetAutoKeyColumns().Split(';');

                    SQLiteCommand cmd = new SQLiteCommand();

                    foreach (string col in identityCols)
                    {
                        cmd.CommandText = "SELECT last_insert_rowid()";

                        // We make sure we enlist in the ongoing transaction, otherwise, we
                        // would most likely deadlock
                        txMgr.Enlist(cmd, this);
                        object o = cmd.ExecuteScalar();                         // Get the Identity Value
                        txMgr.DeEnlist(cmd, this);

                        if (o != null)
                        {
                            e.Row[col] = o;
                        }
                    }

                    e.Row.AcceptChanges();
                }
            }
            catch {}
        }
Пример #4
0
        /// <summary>
        /// Execute the Query and loads your BusinessEntity.
        /// You can pass in the conjustion that will be used between the WHERE parameters, either, "AND" or "OR". "AND" is the default.
        /// Also, if you need to be notified that this is being called override BusinessEntity.OnQueryLoad().
        /// </summary>
        /// <returns>True if at least one record was loaded</returns>
        public bool Load(string conjuction)
        {
            bool      loaded = false;
            DataTable dt     = null;

            try
            {
                if ((_aggregateParameters == null || _aggregateParameters.Count <= 0) &&
                    _resultColumns.Length <= 0 && _countAll == false)
                {
                    this._entity._canSave = true;
                }

                this._entity.OnQueryLoad(conjuction);

                IDbCommand cmd = _Load(conjuction);
                _lastQuery = cmd.CommandText;

                IDbDataAdapter da = this._entity.CreateIDbDataAdapter();
                da.SelectCommand = cmd;

                TransactionMgr txMgr = TransactionMgr.ThreadTransactionMgr();

                dt = new DataTable(_entity.MappingName);

                txMgr.Enlist(cmd, _entity);
                DbDataAdapter dbDataAdapter = this._entity.ConvertIDbDataAdapter(da);
                dbDataAdapter.Fill(dt);
                txMgr.DeEnlist(cmd, _entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                this._entity.DataTable = dt;
                loaded = (dt.Rows.Count > 0);
            }

            return(loaded);
        }