// <Snippet1> public void CreateDataTable() { // ... // create dataSet and mapping // ... DataTable table = mapping.GetDataTableBySchemaAction (dataSet, MissingSchemaAction.Ignore); }
protected override int Fill(DataSet dataSet, string srcTable, IDataReader dataReader, int startRecord, int maxRecords) { if (!dataReader.IsClosed) { DataTableMapping tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction(TableMappings, srcTable, srcTable, MissingMappingAction); if (tableMapping != null) { DataTable dataTable = tableMapping.GetDataTableBySchemaAction(dataSet, MissingSchemaAction); if (dataTable != null) { return(Fill(dataTable, tableMapping, dataReader, startRecord, maxRecords)); } } } return(0); }
public static async Task <int> UpdateAsync <TAdapter>(TAdapter self, DataSet dataSet, string srcTable, CancellationToken cancellationToken) where TAdapter : ICanUpdateAsync, IAdaSchemaMappingAdapter { if (dataSet is null) { throw new ArgumentNullException(nameof(dataSet)); } if (srcTable is null) { throw new ArgumentNullException(nameof(srcTable)); } if (string.IsNullOrEmpty(srcTable)) { throw new ArgumentException(message: "Update: expected a non-empty SourceTable name.", paramName: nameof(srcTable)); } int rowsAffected = 0; DataTableMapping tableMapping = self.GetTableMappingBySchemaAction(sourceTableName: srcTable, dataSetTableName: srcTable, mappingAction: self.UpdateMappingAction); Debug.Assert(null != tableMapping, "null TableMapping when MissingMappingAction.Error"); // the ad-hoc scenario of no dataTable just returns // ad-hoc scenario is defined as MissingSchemaAction.Add or MissingSchemaAction.Ignore MissingSchemaAction schemaAction = self.UpdateSchemaAction; DataTable dataTable = tableMapping.GetDataTableBySchemaAction(dataSet, schemaAction); if (null != dataTable) { rowsAffected = await UpdateFromDataTableAsync(self, dataTable, tableMapping, cancellationToken).ConfigureAwait(false); } else if ((self.TableMappings?.Count ?? 0) == 0 || (-1 == self.TableMappings.IndexOf(tableMapping))) { //throw error since the user didn't explicitly map this tableName to Ignore. throw new InvalidOperationException(string.Format("Update unable to find TableMapping['{0}'] or DataTable '{0}'.", srcTable)); } return(rowsAffected); }