Exemple #1
0
        }                 // Generate

        static internal bool Generate(
            DbDataAdapter dbDataAdapter,
            DataTable dt,
            string sourceTableName,
            string datasetTableName)
        {
            if (sourceTableName.Length == 0)              // Source Table name is invalid
            {
                return(false);
            }
            if (datasetTableName.Length == 0)              // DataSet Table name is invalid
            {
                return(false);
            }

            DataTableMappingCollection mapList = dbDataAdapter.TableMappings;

            mapList.Clear();
            DataTableMapping map = mapList.Add(sourceTableName, datasetTableName);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                System.Data.DataRow datarow = dt.Rows[i];
                string sourceCol            = ((string)datarow[SOURCE_COLUMNS]).Trim();
                string datasetCol           = ((string)datarow[DATASET_COLUMNS]).Trim();
                if (sourceCol.Length == 0 ||                   // drop empty mappings
                    datasetCol.Length == 0)
                {
                    continue;
                }
                map.ColumnMappings.Add(sourceCol, datasetCol);
            }

            return(true);
        }          // Generate
Exemple #2
0
 // <Snippet1>
 public void PushIntoArray()
 {
     // ...
     // create DataTableMappingCollection collection mappings
     // ...
     DataTableMapping[] tables = {};
     mappings.CopyTo(tables, 0);
     mappings.Clear();
 }
Exemple #3
0
        /// <summary>
        /// OK Button event handler.
        /// Copy the column mappings back the TableMapping collection.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonOK_Click(object sender, System.EventArgs e)
        {
            System.Data.DataTable dt =
                (System.Data.DataTable) this.dataGrid1.DataSource;
            if (dt == null)
            {
                return;
            }

            dt.AcceptChanges();

            string sourceTable  = comboBoxSourceTable.Text.Trim();
            string datasetTable = textBoxDatasetTable.Text.Trim();

            if (sourceTable.Length == 0)
            {
                System.Windows.Forms.MessageBox.Show(
                    "Source Table name is invalid.",
                    "Table Mappings");
                return;
            }
            if (datasetTable.Length == 0)
            {
                System.Windows.Forms.MessageBox.Show(
                    "DataSet Table name is invalid.",
                    "Table Mappings");
                return;
            }

            DataTableMappingCollection mapList = this.dbAdapter.TableMappings;

            mapList.Clear();
            DataTableMapping map = mapList.Add(sourceTable, datasetTable);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                System.Data.DataRow datarow = dt.Rows[i];
                string sourceCol            =
                    ((string)datarow[TableMappings.SOURCE_COLUMNS]).Trim();
                string datasetCol =
                    ((string)datarow[TableMappings.DATASET_COLUMNS]).Trim();
                if (sourceCol.Length == 0 ||                   // drop empty mappings
                    datasetCol.Length == 0)
                {
                    continue;
                }
                map.ColumnMappings.Add(sourceCol, datasetCol);
            }
        }
Exemple #4
0
 public void Dispose()
 {
     _tableMapCollection.Clear();
 }
 public void Clean()
 {
     tableMapCollection.Clear();
 }