Ejemplo n.º 1
0
        /// <summary>
        /// Overridden. Raises the RowUpdated event.
        /// </summary>
        /// <param name="value">A MySqlRowUpdatedEventArgs that contains the event data. </param>
        override protected void OnRowUpdated(RowUpdatedEventArgs value)
        {
            MySqlRowUpdatedEventHandler handler = (MySqlRowUpdatedEventHandler)Events[EventRowUpdated];

            if ((null != handler) && (value is MySqlRowUpdatedEventArgs))
            {
                handler(this, (MySqlRowUpdatedEventArgs)value);
            }
        }
Ejemplo n.º 2
0
        protected override void OnRowUpdated(RowUpdatedEventArgs value)
        {
            MySqlRowUpdatedEventArgs    mySqlRowUpdatedEventArgs    = value as MySqlRowUpdatedEventArgs;
            MySqlRowUpdatedEventHandler mySqlRowUpdatedEventHandler = (MySqlRowUpdatedEventHandler)base.Events[MySqlDataAdapter.EventRowUpdated];

            if (mySqlRowUpdatedEventHandler != null && mySqlRowUpdatedEventArgs != null)
            {
                mySqlRowUpdatedEventHandler(this, mySqlRowUpdatedEventArgs);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Overridden. Raises the RowUpdated event.
        /// </summary>
        /// <param name="value">A MySqlRowUpdatedEventArgs that contains the event data. </param>
        override protected void OnRowUpdated(RowUpdatedEventArgs value)
        {
            MySqlRowUpdatedEventArgs margs = (value as MySqlRowUpdatedEventArgs);
            //args.Command.CommandText = savedSql;

            MySqlRowUpdatedEventHandler handler = (MySqlRowUpdatedEventHandler)Events[EventRowUpdated];

            if ((null != handler) && (margs != null))
            {
                handler(this, margs);
            }
        }
Ejemplo n.º 4
0
        /* Connect to the database specified in the connection string, build non-
         * select queries from the provided query, update the database, and return
         * the number of affected rows.  Return null if any steps fail. */

        private async Task <int?> SaveTableChangesAsync(string connect, string select, DataTable table)
        {
            if (connect == null)
            {
                return(null);
            }

            try
            {
                using (var connection = new MySqlConnection(connect))
                    using (var adapter = new MySqlDataAdapter(select, connection))
                        using (var builder = new MySqlCommandBuilder(adapter))
                        {
                            /* This feels like a cludge, but it is unfortunately necessary.  Update
                             * commands called when the data adapter affects record insertions do
                             * NOT return the newly created ID and do not update the added row
                             * in the data table as a result.  This results in added records that
                             * cannot be deleted.  Also, once a failed deletion occurs, accept changes
                             * called after any other operation that works will still fail becuase the
                             * deletion is queued to occur.  This handler checks for an insertion after
                             * a row update occurs, and if an insertion occured, it does what the
                             * data adapter should be doing in the first place. */

                            MySqlRowUpdatedEventHandler handler = null;

                            handler = (object sender, MySqlRowUpdatedEventArgs args) =>
                            {
                                if (args.Command.CommandText.Contains("INSERT"))
                                {
                                    table.Rows[table.Rows.Count - 1]["id"] = args.Command.LastInsertedId;
                                }

                                adapter.RowUpdated -= handler;
                            };

                            adapter.RowUpdated += handler;

                            return(await adapter.UpdateAsync(table));
                        }
            }
            catch // ( Exception e )
            {
                // MessageBox.Show( e.Message );

                return(null);
            }
        }