Beispiel #1
0
        private DbDataAdapter GetDataAdapterClone(DbDataAdapter oldAdapter)
        {
            DbDataAdapter adapter =
                DataAdapterUtil.GetDataAdapterClone(oldAdapter);

            IDbCommand selectCommand = ((IDbDataAdapter)adapter).SelectCommand;

            if (selectCommand == null ||
                selectCommand.CommandText == null ||
                selectCommand.CommandText.Length == 0)
            {
                MessageBox.Show("Adapter's SelectCommand is not configured",
                                "Generate " + DATASETNAME_PREFIX);
                return(null);
            }

            IDbConnection connection = selectCommand.Connection;

            if (connection == null ||
                connection.ConnectionString == null ||
                connection.ConnectionString.Length == 0)
            {
                MessageBox.Show("Adapter's SelectCommand.Connection is not configured",
                                "Generate " + DATASETNAME_PREFIX);
                return(null);
            }

            return(adapter);
        }          // GetDataAdapterClone
Beispiel #2
0
        /// <summary>
        /// Reset button event handler.
        /// Discard the existing mappings in the datagrid and
        /// build a new set from the database.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonReset_Click(object sender, System.EventArgs e)
        {
            if (this.dbAdapter == null)
            {
                System.Windows.Forms.MessageBox.Show(
                    "Data Adapter is null; Table mappings is not available.",
                    "Table Mappings");
                return;
            }

            DataTableMappingCollection mapList = this.dbAdapter.TableMappings;

            if (mapList == null)
            {
                System.Windows.Forms.MessageBox.Show(
                    "Data Adapter's Table mappings are null and are not available.",
                    "Table Mappings");
                return;
            }

            System.Data.DataTable dt;
            dt = TableMappings.BuildMapFromDatabase(
                DataAdapterUtil.GetDataAdapterClone(this.dbAdapter));
            textBoxDatasetTable.Text =
                TableMappings.BuildDataSetNameFromCommand(this.dbAdapter);

            dt.AcceptChanges();
            this.dataGrid1.DataSource = dt;
        }  // buttonReset_Click
Beispiel #3
0
        static internal bool Generate(DbDataAdapter origDbDataAdapter)
        {
            if (origDbDataAdapter == null)
            {
                return(false);
            }

            DbDataAdapter dbAdapter =
                DataAdapterUtil.GetDataAdapterClone(origDbDataAdapter);
            IDbDataAdapter dataAdapter = (IDbDataAdapter)dbAdapter;
            IDbCommand     dbCommand   = dataAdapter.SelectCommand;

            // safety check for a missing or incomplete Command
            if (dbCommand == null ||
                dbCommand.CommandText == null ||
                dbCommand.CommandText.Trim().Length == 0)
            {
                return(false);
            }

            // safety check for a missing Connection
            if (dbCommand.Connection == null)
            {
                return(false);
            }

            string cmdText = dbCommand.CommandText;

            // make a schema table that the DbAdapter can fill in
            DataTable dt;

            // build the DataTable with the column mapping
            dt = BuildMapFromDatabase(dbAdapter);

            // move the mapping in the data table to adapter.TableMappings
            Generate(
                origDbDataAdapter, dt,
                "Table", BuildDataSetNameFromCommand(cmdText));

            return(true); // return with all went well
        }                 // Generate