public int Update (DataRow [] dataRows)
{
if (dataRows == null)
throw new ArgumentNullException("dataRows");
if (dataRows.Length == 0)
return 0;
if (dataRows [0] == null)
throw new ArgumentException("dataRows[0].");
DataTable table = dataRows [0].Table;
if (table == null)
throw new ArgumentException("table is null reference.");
// all rows must be in the same table
for (int i = 0; i < dataRows.Length; i++) {
if (dataRows [i] == null)
throw new ArgumentException ("dataRows[" + i + "].");
if (dataRows [i].Table != table)
throw new ArgumentException(
" DataRow["
+ i
+ "] is from a different DataTable than DataRow[0].");
}
// get table mapping for this rows
DataTableMapping tableMapping = TableMappings.GetByDataSetTable(table.TableName);
if (tableMapping == null) {
tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction(
TableMappings,
table.TableName,
table.TableName,
MissingMappingAction);
if (tableMapping != null) {
foreach (DataColumn col in table.Columns) {
if (tableMapping.ColumnMappings.IndexOf (col.ColumnName) >= 0)
continue;
DataColumnMapping columnMapping = DataColumnMappingCollection.GetColumnMappingBySchemaAction (tableMapping.ColumnMappings, col.ColumnName, MissingMappingAction);
if (columnMapping == null)
columnMapping = new DataColumnMapping (col.ColumnName, col.ColumnName);
tableMapping.ColumnMappings.Add (columnMapping);
}
} else {
ArrayList cmc = new ArrayList ();
foreach (DataColumn col in table.Columns)
cmc.Add (new DataColumnMapping (col.ColumnName, col.ColumnName));
tableMapping =
new DataTableMapping (
table.TableName,
table.TableName,
cmc.ToArray (typeof (DataColumnMapping)) as DataColumnMapping []);
}
}
DataRow[] copy = table.NewRowArray (dataRows.Length);
Array.Copy (dataRows, 0, copy, 0, dataRows.Length);
return Update (copy, tableMapping);
}