public void FillDataSetNoParams() { PopulateTestObjectsTable(); string sql = ValidateTestObjects(4); DataSet dataSet; dataSet = new DataSet(); adoOperations.DataSetFill(dataSet, CommandType.Text, sql, new string[] { "TestObjects" }); Assert.AreEqual(1, dataSet.Tables.Count); Assert.AreEqual(4, dataSet.Tables["TestObjects"].Rows.Count); dataSet = new DataSet(); DataTableMappingCollection mappingCollection = new DataTableMappingCollection(); DataTableMapping testObjectsMapping = mappingCollection.Add("Table", "TestObjects"); testObjectsMapping.ColumnMappings.Add("TestObjectNo", "UserID"); testObjectsMapping.ColumnMappings.Add("Name", "UserName"); adoOperations.DataSetFill(dataSet, CommandType.Text, sql, mappingCollection); Assert.AreEqual(1, dataSet.Tables.Count); Assert.AreEqual(4, dataSet.Tables["TestObjects"].Rows.Count); foreach (DataRow testObjectRow in dataSet.Tables["TestObjects"].Rows) { Assert.IsNotNull(testObjectRow["UserID"]); Assert.IsNotNull(testObjectRow["Age"]); Assert.IsNotNull(testObjectRow["UserName"]); } }
public void DataSetFillNoParams() { String sql = "select USER_ID, USER_NAME from USER_TABLE"; DataSet dataSet = new DataSet(); adoOperations.DataSetFill(dataSet, CommandType.Text, sql); Assert.AreEqual(1, dataSet.Tables.Count); Assert.AreEqual(18, dataSet.Tables["Table"].Rows.Count); dataSet = new DataSet(); adoOperations.DataSetFill(dataSet, CommandType.Text, sql, new string[] { "TestObjects" }); Assert.AreEqual(1, dataSet.Tables.Count); Assert.AreEqual(18, dataSet.Tables["TestObjects"].Rows.Count); dataSet = new DataSet(); DataTableMappingCollection mappingCollection = new DataTableMappingCollection(); DataTableMapping testObjectsMapping = mappingCollection.Add("Table", "TestObjects"); testObjectsMapping.ColumnMappings.Add("USER_ID", "UserID"); testObjectsMapping.ColumnMappings.Add("USER_NAME", "UserName"); adoOperations.DataSetFill(dataSet, CommandType.Text, sql, mappingCollection); Assert.AreEqual(1, dataSet.Tables.Count); Assert.AreEqual(18, dataSet.Tables["TestObjects"].Rows.Count); foreach (DataRow testObjectRow in dataSet.Tables["TestObjects"].Rows) { Assert.IsNotNull(testObjectRow["UserID"]); Assert.IsNotNull(testObjectRow["UserName"]); } }
private ITableMappingCollection DoCreateMappingCollection(string[] dataSetTableNames) { DataTableMappingCollection mappingCollection; if (dataSetTableNames == null) { dataSetTableNames = new string[] { "Table" }; } foreach (string tableName in dataSetTableNames) { if (StringUtils.IsNullOrEmpty(tableName)) { throw new ArgumentException("TableName for DataTable mapping can not be null or empty"); } } mappingCollection = new DataTableMappingCollection(); int counter = 0; bool isFirstTable = true; foreach (string dataSetTableName in dataSetTableNames) { string sourceTableName; if (isFirstTable) { sourceTableName = "Table"; isFirstTable = false; } else { sourceTableName = "Table" + ++counter; } mappingCollection.Add(sourceTableName, dataSetTableName); } return(mappingCollection); }
} // 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
// <Snippet1> public void CreateTableMappings() { DataTableMappingCollection mappings = new DataTableMappingCollection(); mappings.Add("Categories", "DataCategories"); mappings.Add("Orders", "DataOrders"); mappings.Add("Products", "DataProducts"); string message = "TableMappings:\n"; for (int i = 0; i < mappings.Count; i++) { message += i.ToString() + " " + mappings[i].ToString() + "\n"; } Console.WriteLine(message); }
public void Add() { int t = _tableMapCollection.Add(_tabs[0]); Assert.Equal(0, t); bool eq1 = _tabs[0].Equals(_tableMapCollection[0]); Assert.True(eq1); Assert.Equal(1, _tableMapCollection.Count); DataTableMapping tab2; tab2 = _tableMapCollection.Add("sourceEmployees", "dataSetEmployees"); bool eq2 = tab2.Equals(_tableMapCollection[1]); Assert.True(eq2); Assert.Equal(2, _tableMapCollection.Count); }
/// ////////////////////////////////////////////////// public C2iDataAdapterForType(IDatabaseConnexion connexion, Type typeObjets, CFiltreData filtre, params string[] strExclusions) { m_connexion = connexion; m_typeObjets = typeObjets; m_structure = CStructureTable.GetStructure(m_typeObjets); m_tableMapping.Add(new DataTableMapping(m_structure.NomTableInDb, m_structure.NomTable)); m_filtre = filtre; foreach (string strChamp in strExclusions) { m_tableExclusions[strChamp] = true; } }
// <Snippet1> public void AddDataTableMapping() { // ... // create tableMappings // ... DataTableMapping mapping = new DataTableMapping("Categories", "DataCategories"); tableMappings.Add((Object)mapping); Console.WriteLine("Table {0} added to {1} table mapping collection.", mapping.ToString(), tableMappings.ToString()); }
// <Snippet1> public void AddDataTableMapping() { // ... // create mappings // ... DataTableMapping mapping = new DataTableMapping("Categories", "DataCategories"); mappings.Add((Object)mapping); Console.WriteLine("Table " + mapping.ToString() + " added to " + "table mapping collection " + mappings.ToString()); }
public void IListIndexer() { IList list = new DataTableMappingCollection(); var mapping = new DataTableMapping("source", "dataSet"); Assert.Throws <IndexOutOfRangeException>(() => { var x = list[0]; }); Assert.Throws <IndexOutOfRangeException>(() => { list[0] = mapping; }); list.Add(mapping); Assert.Same(mapping, list[0]); Assert.Throws <ArgumentNullException>(() => { list[0] = null; }); Assert.Throws <InvalidCastException>(() => { list[0] = "invalid"; }); list[0] = new DataTableMapping("source2", "dataSet2"); Assert.NotSame(mapping, list[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); } }
/// <summary> /// 创建默认表列映射 /// </summary> /// <param name="ds"></param> /// <returns></returns> public static System.Data.Common.DataTableMappingCollection CreateDefaultMapping(System.Data.DataSet ds) { DataTableMappingCollection rtn = new DataTableMappingCollection(); foreach (System.Data.DataTable dt in ds.Tables) { DataTableMapping dtm = rtn.Add(dt.TableName, dt.TableName); foreach (DataColumn dc in dt.Columns) { dtm.ColumnMappings.Add(dc.ColumnName, dc.ColumnName); } } return(rtn); }
// <Snippet1> public void ChangedMyMind() { // ... // create mappings and mapping // ... if (mappings.Contains((Object)mapping)) { mappings.Remove((Object)mapping); } else { mappings.Add((Object)mapping); Console.WriteLine("Index of new mapping: " + mappings.IndexOf((Object)mapping)); } }
public void ITableMappingCollectionIndexer() { ITableMappingCollection collection = new DataTableMappingCollection(); Assert.Throws <IndexOutOfRangeException>(() => { var x = collection["source"]; }); Assert.Throws <IndexOutOfRangeException>(() => { collection["source"] = new DataTableMapping(); }); ITableMapping mapping = collection.Add("source", "dataSet"); Assert.Same(mapping, collection["source"]); Assert.Same(mapping, collection.GetByDataSetTable("dataSet")); Assert.Throws <ArgumentNullException>(() => { collection["source"] = null; }); Assert.Throws <InvalidCastException>(() => { collection["source"] = "invalid"; }); ITableMapping mapping2 = new DataTableMapping("source2", "dataSet2"); collection["source"] = mapping2; Assert.Single(collection); Assert.Same(mapping2, collection["source2"]); Assert.Throws <IndexOutOfRangeException>(() => collection.GetByDataSetTable("dataSet")); }
private void CloneFrom(DataAdapter from) { _acceptChangesDuringUpdate = from._acceptChangesDuringUpdate; _acceptChangesDuringUpdateAfterInsert = from._acceptChangesDuringUpdateAfterInsert; _continueUpdateOnError = from._continueUpdateOnError; _returnProviderSpecificTypes = from._returnProviderSpecificTypes; // WebData 101795 _acceptChangesDuringFill = from._acceptChangesDuringFill; _fillLoadOption = from._fillLoadOption; _missingMappingAction = from._missingMappingAction; _missingSchemaAction = from._missingSchemaAction; if ((null != from._tableMappings) && (0 < from.TableMappings.Count)) { DataTableMappingCollection parameters = this.TableMappings; foreach (object parameter in from.TableMappings) { parameters.Add((parameter is ICloneable) ? ((ICloneable)parameter).Clone() : parameter); } } }
public void Add() { int t = tableMapCollection.Add((Object)tabs[0]); Assert.AreEqual(0, t, "test1"); bool eq1 = tabs[0].Equals(tableMapCollection[0]); Assert.AreEqual(true, eq1, "test2"); Assert.AreEqual(1, tableMapCollection.Count, "test3"); DataTableMapping tab2; tab2 = tableMapCollection.Add("sourceEmployees", "dataSetEmployees"); bool eq2 = tab2.Equals(tableMapCollection[1]); Assert.AreEqual(true, eq2, "test4"); Assert.AreEqual(2, tableMapCollection.Count, "test5"); }