2 // System.Data.Common.DbDataAdapter.cs
5 // Rodrigo Moya (rodrigo@ximian.com)
6 // Tim Coleman (tim@timcoleman.com)
7 // Sureshkumar T <tsureshkumar@novell.com>
10 // Copyright (C) Tim Coleman, 2002-2003
14 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
16 // Permission is hereby granted, free of charge, to any person obtaining
17 // a copy of this software and associated documentation files (the
18 // "Software"), to deal in the Software without restriction, including
19 // without limitation the rights to use, copy, modify, merge, publish,
20 // distribute, sublicense, and/or sell copies of the Software, and to
21 // permit persons to whom the Software is furnished to do so, subject to
22 // the following conditions:
24 // The above copyright notice and this permission notice shall be
25 // included in all copies or substantial portions of the Software.
27 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
32 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 using System.Collections;
38 using System.ComponentModel;
40 using System.Reflection;
41 using System.Runtime.InteropServices;
43 namespace System.Data.Common
46 public abstract class DbDataAdapter : DataAdapter, IDbDataAdapter, IDataAdapter, ICloneable
48 public abstract class DbDataAdapter : DataAdapter, ICloneable
53 public const string DefaultSourceTableName = "Table";
54 const string DefaultSourceColumnName = "Column";
55 CommandBehavior _behavior = CommandBehavior.Default;
58 IDbCommand _selectCommand;
59 IDbCommand _updateCommand;
60 IDbCommand _deleteCommand;
61 IDbCommand _insertCommand;
68 protected DbDataAdapter ()
72 protected DbDataAdapter (DbDataAdapter adapter) : base (adapter)
81 protected internal CommandBehavior FillCommandBehavior {
82 get { return _behavior; }
83 set { _behavior = value; }
86 IDbCommand IDbDataAdapter.SelectCommand {
87 get { return _selectCommand; }
88 set { _selectCommand = value; }
91 IDbCommand IDbDataAdapter.UpdateCommand{
92 get { return _updateCommand; }
93 set { _updateCommand = value; }
96 IDbCommand IDbDataAdapter.DeleteCommand{
97 get { return _deleteCommand; }
98 set { _deleteCommand = value; }
101 IDbCommand IDbDataAdapter.InsertCommand{
102 get { return _insertCommand; }
103 set { _insertCommand = value; }
107 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
108 public DbCommand SelectCommand {
109 get { return (DbCommand) ((IDbDataAdapter) this).SelectCommand; }
110 set { ((IDbDataAdapter) this).SelectCommand = value; }
114 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
115 public DbCommand DeleteCommand {
116 get { return (DbCommand) ((IDbDataAdapter) this).DeleteCommand; }
117 set { ((IDbDataAdapter) this).DeleteCommand = value; }
121 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
122 public DbCommand InsertCommand {
123 get { return (DbCommand) ((IDbDataAdapter) this).InsertCommand; }
124 set { ((IDbDataAdapter) this).InsertCommand = value; }
128 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
129 public DbCommand UpdateCommand {
130 get { return (DbCommand) ((IDbDataAdapter) this).UpdateCommand; }
131 set { ((IDbDataAdapter) this).UpdateCommand = value; }
135 public virtual int UpdateBatchSize {
139 throw new NotSupportedException ();
143 IDbCommand SelectCommand {
144 get { return ((IDbDataAdapter) this).SelectCommand; }
148 #endregion // Properties
152 #if ONLY_1_0 || ONLY_1_1
153 [DataCategory ("Fill")]
154 [DataSysDescription ("Event triggered when a recoverable error occurs during Fill.")]
155 public event FillErrorEventHandler FillError;
163 protected virtual RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command,
164 StatementType statementType,
165 DataTableMapping tableMapping)
167 return new RowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
170 protected virtual RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command,
171 StatementType statementType,
172 DataTableMapping tableMapping)
174 return new RowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
177 protected virtual void OnRowUpdated (RowUpdatedEventArgs value)
179 if (Events ["RowUpdated"] != null) {
180 Delegate [] rowUpdatedList = Events ["RowUpdated"].GetInvocationList ();
181 foreach (Delegate rowUpdated in rowUpdatedList) {
182 MethodInfo rowUpdatedMethod = rowUpdated.Method;
183 rowUpdatedMethod.Invoke (value, null);
188 protected virtual void OnRowUpdating (RowUpdatingEventArgs value)
190 if (Events ["RowUpdating"] != null) {
191 Delegate [] rowUpdatingList = Events ["RowUpdating"].GetInvocationList ();
192 foreach (Delegate rowUpdating in rowUpdatingList) {
193 MethodInfo rowUpdatingMethod = rowUpdating.Method;
194 rowUpdatingMethod.Invoke (value, null);
199 protected abstract RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command,
200 StatementType statementType,
201 DataTableMapping tableMapping);
203 protected abstract RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command,
204 StatementType statementType,
205 DataTableMapping tableMapping);
207 protected abstract void OnRowUpdated (RowUpdatedEventArgs value);
208 protected abstract void OnRowUpdating (RowUpdatingEventArgs value);
211 protected override void Dispose (bool disposing)
214 IDbDataAdapter da = (IDbDataAdapter) this;
215 if (da.SelectCommand != null) {
216 da.SelectCommand.Dispose();
217 da.SelectCommand = null;
219 if (da.InsertCommand != null) {
220 da.InsertCommand.Dispose();
221 da.InsertCommand = null;
223 if (da.UpdateCommand != null) {
224 da.UpdateCommand.Dispose();
225 da.UpdateCommand = null;
227 if (da.DeleteCommand != null) {
228 da.DeleteCommand.Dispose();
229 da.DeleteCommand = null;
234 public override int Fill (DataSet dataSet)
236 return Fill (dataSet, 0, 0, DefaultSourceTableName, ((IDbDataAdapter) this).SelectCommand, _behavior);
239 public int Fill (DataTable dataTable)
241 if (dataTable == null)
242 throw new ArgumentNullException ("DataTable");
244 return Fill (dataTable, ((IDbDataAdapter) this).SelectCommand, _behavior);
247 public int Fill (DataSet dataSet, string srcTable)
249 return Fill (dataSet, 0, 0, srcTable, ((IDbDataAdapter) this).SelectCommand, _behavior);
253 protected virtual int Fill (DataTable dataTable, IDataReader dataReader)
255 return base.FillInternal (dataTable, dataReader);
259 protected virtual int Fill (DataTable dataTable, IDbCommand command, CommandBehavior behavior)
261 CommandBehavior commandBehavior = behavior;
263 // first see that the connection is not close.
264 if (command.Connection.State == ConnectionState.Closed) {
265 command.Connection.Open ();
266 commandBehavior |= CommandBehavior.CloseConnection;
268 return Fill (dataTable, command.ExecuteReader (commandBehavior));
271 public int Fill (DataSet dataSet, int startRecord, int maxRecords, string srcTable)
273 return this.Fill (dataSet, startRecord, maxRecords, srcTable, ((IDbDataAdapter) this).SelectCommand, _behavior);
278 public int Fill (int startRecord, int maxRecords, params DataTable[] dataTables)
280 throw new NotImplementedException ();
284 protected virtual int Fill (DataTable[] dataTables, int startRecord, int maxRecords, IDbCommand command, CommandBehavior behavior)
286 throw new NotImplementedException ();
289 protected virtual int Fill (DataSet dataSet, string srcTable, IDataReader dataReader, int startRecord, int maxRecords)
291 return base.FillInternal (dataSet, srcTable, dataReader, startRecord, maxRecords);
295 protected virtual int Fill (DataSet dataSet, int startRecord, int maxRecords, string srcTable, IDbCommand command, CommandBehavior behavior)
297 if (command.Connection == null)
298 throw new InvalidOperationException ("Connection state is closed");
300 if (MissingSchemaAction == MissingSchemaAction.AddWithKey)
301 behavior |= CommandBehavior.KeyInfo;
302 CommandBehavior commandBehavior = behavior;
304 if (command.Connection.State == ConnectionState.Closed) {
305 command.Connection.Open ();
306 commandBehavior |= CommandBehavior.CloseConnection;
308 return Fill (dataSet, srcTable, command.ExecuteReader (commandBehavior),
309 startRecord, maxRecords);
314 /// Fills the given datatable using values from reader. if a value
315 /// for a column is null, that will be filled with default value.
317 /// <returns>No. of rows affected </returns>
318 internal static int FillFromReader (DataTable table,
323 LoadOption loadOption
326 if (reader.FieldCount == 0)
329 for (int i = 0; i < start; i++)
333 object [] values = new object [mapping.Length];
334 while (reader.Read () && (length == 0 || counter < length)) {
335 for (int i = 0 ; i < mapping.Length; i++)
336 values [i] = mapping [i] < 0 ? null : reader [mapping [i]];
337 table.BeginLoadData ();
338 table.LoadDataRow (values, loadOption);
339 table.EndLoadData ();
345 internal static int FillFromReader (DataTable table,
350 LoadOption loadOption,
351 FillErrorEventHandler errorHandler)
353 if (reader.FieldCount == 0)
356 for (int i = 0; i < start; i++)
360 object [] values = new object [mapping.Length];
361 while (reader.Read () && (length == 0 || counter < length)) {
362 for (int i = 0 ; i < mapping.Length; i++)
363 values [i] = mapping [i] < 0 ? null : reader [mapping [i]];
364 table.BeginLoadData ();
366 table.LoadDataRow (values, loadOption);
367 } catch (Exception e) {
368 FillErrorEventArgs args = new FillErrorEventArgs (table, values);
370 args.Continue = false;
371 errorHandler (table, args);
372 // if args.Continue is not set to true or if a handler is not set, rethrow the error..
376 table.EndLoadData ();
383 public override DataTable [] FillSchema (DataSet dataSet, SchemaType schemaType)
385 return FillSchema (dataSet, schemaType, ((IDbDataAdapter) this).SelectCommand, DefaultSourceTableName, _behavior);
388 public DataTable FillSchema (DataTable dataTable, SchemaType schemaType)
390 return FillSchema (dataTable, schemaType, ((IDbDataAdapter) this).SelectCommand, _behavior);
393 public DataTable [] FillSchema (DataSet dataSet, SchemaType schemaType, string srcTable)
395 return FillSchema (dataSet, schemaType, ((IDbDataAdapter) this).SelectCommand, srcTable, _behavior);
398 protected virtual DataTable FillSchema (DataTable dataTable, SchemaType schemaType, IDbCommand command, CommandBehavior behavior)
400 if (dataTable == null)
401 throw new ArgumentNullException ("DataTable");
403 behavior |= CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo;
404 if (command.Connection.State == ConnectionState.Closed) {
405 command.Connection.Open ();
406 behavior |= CommandBehavior.CloseConnection;
409 IDataReader reader = command.ExecuteReader (behavior);
411 string tableName = SetupSchema (schemaType, dataTable.TableName);
412 if (tableName != null) {
413 // FillSchema should add the KeyInfo unless MissingSchemaAction
414 // is set to Ignore or Error.
415 MissingSchemaAction schemaAction = MissingSchemaAction;
416 if (!(schemaAction == MissingSchemaAction.Ignore ||
417 schemaAction == MissingSchemaAction.Error))
418 schemaAction = MissingSchemaAction.AddWithKey;
420 BuildSchema (reader, dataTable, schemaType, schemaAction,
421 MissingMappingAction, TableMappings);
429 protected virtual DataTable[] FillSchema (DataSet dataSet, SchemaType schemaType, IDbCommand command, string srcTable, CommandBehavior behavior)
432 throw new ArgumentNullException ("DataSet");
434 behavior |= CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo;
435 if (command.Connection.State == ConnectionState.Closed) {
436 command.Connection.Open ();
437 behavior |= CommandBehavior.CloseConnection;
440 IDataReader reader = command.ExecuteReader (behavior);
441 ArrayList output = new ArrayList ();
442 string tableName = srcTable;
446 // FillSchema should add the KeyInfo unless MissingSchemaAction
447 // is set to Ignore or Error.
448 MissingSchemaAction schemaAction = MissingSchemaAction;
449 if (!(MissingSchemaAction == MissingSchemaAction.Ignore ||
450 MissingSchemaAction == MissingSchemaAction.Error))
451 schemaAction = MissingSchemaAction.AddWithKey;
454 tableName = SetupSchema (schemaType, tableName);
455 if (tableName != null) {
456 if (dataSet.Tables.Contains (tableName))
457 table = dataSet.Tables [tableName];
459 // Do not create schema if MissingSchemAction is set to Ignore
460 if (this.MissingSchemaAction == MissingSchemaAction.Ignore)
462 table = dataSet.Tables.Add (tableName);
465 BuildSchema (reader, table, schemaType, schemaAction,
466 MissingMappingAction, TableMappings);
468 tableName = String.Format ("{0}{1}", srcTable, ++index);
470 }while (reader.NextResult ());
474 return (DataTable []) output.ToArray (typeof (DataTable));
477 [EditorBrowsable (EditorBrowsableState.Advanced)]
478 public override IDataParameter[] GetFillParameters ()
480 IDataParameter[] parameters = new IDataParameter [SelectCommand.Parameters.Count];
481 SelectCommand.Parameters.CopyTo (parameters, 0);
486 [Obsolete ("use 'protected DbDataAdapter(DbDataAdapter)' ctor")]
487 object ICloneable.Clone ()
489 throw new NotImplementedException ();
492 public int Update (DataRow [] dataRows)
494 if (dataRows == null)
495 throw new ArgumentNullException("dataRows");
497 if (dataRows.Length == 0)
500 if (dataRows [0] == null)
501 throw new ArgumentException("dataRows[0].");
503 DataTable table = dataRows [0].Table;
505 throw new ArgumentException("table is null reference.");
507 // all rows must be in the same table
508 for (int i = 0; i < dataRows.Length; i++) {
509 if (dataRows [i] == null)
510 throw new ArgumentException ("dataRows[" + i + "].");
511 if (dataRows [i].Table != table)
512 throw new ArgumentException(
515 + "] is from a different DataTable than DataRow[0].");
518 // get table mapping for this rows
519 DataTableMapping tableMapping = TableMappings.GetByDataSetTable(table.TableName);
520 if (tableMapping == null) {
521 tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction(
525 MissingMappingAction);
526 if (tableMapping != null) {
527 foreach (DataColumn col in table.Columns) {
528 if (tableMapping.ColumnMappings.IndexOf (col.ColumnName) >= 0)
530 DataColumnMapping columnMapping = DataColumnMappingCollection.GetColumnMappingBySchemaAction (tableMapping.ColumnMappings, col.ColumnName, MissingMappingAction);
531 if (columnMapping == null)
532 columnMapping = new DataColumnMapping (col.ColumnName, col.ColumnName);
533 tableMapping.ColumnMappings.Add (columnMapping);
536 ArrayList cmc = new ArrayList ();
537 foreach (DataColumn col in table.Columns)
538 cmc.Add (new DataColumnMapping (col.ColumnName, col.ColumnName));
540 new DataTableMapping (
543 cmc.ToArray (typeof (DataColumnMapping)) as DataColumnMapping []);
547 DataRow[] copy = table.NewRowArray (dataRows.Length);
548 Array.Copy (dataRows, 0, copy, 0, dataRows.Length);
549 return Update (copy, tableMapping);
552 public override int Update (DataSet dataSet)
554 return Update (dataSet, DefaultSourceTableName);
557 public int Update (DataTable dataTable)
560 int index = TableMappings.IndexOfDataSetTable (dataTable.TableName);
562 throw new ArgumentException ();
563 return Update (dataTable, TableMappings [index]);
565 DataTableMapping tableMapping = TableMappings.GetByDataSetTable (dataTable.TableName);
566 if (tableMapping == null) {
567 tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction (
571 MissingMappingAction);
572 if (tableMapping != null) {
573 foreach (DataColumn col in dataTable.Columns) {
574 if (tableMapping.ColumnMappings.IndexOf (col.ColumnName) >= 0)
576 DataColumnMapping columnMapping = DataColumnMappingCollection.GetColumnMappingBySchemaAction (tableMapping.ColumnMappings, col.ColumnName, MissingMappingAction);
577 if (columnMapping == null)
578 columnMapping = new DataColumnMapping (col.ColumnName, col.ColumnName);
579 tableMapping.ColumnMappings.Add (columnMapping);
582 ArrayList cmc = new ArrayList ();
583 foreach (DataColumn col in dataTable.Columns)
584 cmc.Add (new DataColumnMapping (col.ColumnName, col.ColumnName));
586 new DataTableMapping (
589 cmc.ToArray (typeof (DataColumnMapping)) as DataColumnMapping []);
592 return Update (dataTable, tableMapping);
595 private int Update (DataTable dataTable, DataTableMapping tableMapping)
597 DataRow [] rows = dataTable.NewRowArray(dataTable.Rows.Count);
598 dataTable.Rows.CopyTo (rows, 0);
599 return Update (rows, tableMapping);
602 protected virtual int Update (DataRow [] dataRows, DataTableMapping tableMapping)
605 foreach (DataRow row in dataRows) {
606 StatementType statementType = StatementType.Update;
607 IDbCommand command = null;
608 string commandName = String.Empty;
610 switch (row.RowState) {
611 case DataRowState.Added:
612 statementType = StatementType.Insert;
613 command = ((IDbDataAdapter) this).InsertCommand;
614 commandName = "Insert";
616 case DataRowState.Deleted:
617 statementType = StatementType.Delete;
618 command = ((IDbDataAdapter) this).DeleteCommand;
619 commandName = "Delete";
621 case DataRowState.Modified:
622 statementType = StatementType.Update;
623 command = ((IDbDataAdapter) this).UpdateCommand;
624 commandName = "Update";
626 case DataRowState.Unchanged:
627 case DataRowState.Detached:
631 RowUpdatingEventArgs argsUpdating = CreateRowUpdatingEvent (row, command, statementType, tableMapping);
633 OnRowUpdating (argsUpdating);
634 switch (argsUpdating.Status) {
635 case UpdateStatus.Continue :
636 //continue in update operation
638 case UpdateStatus.ErrorsOccurred :
639 if (argsUpdating.Errors == null)
640 argsUpdating.Errors = ExceptionHelper.RowUpdatedError();
641 row.RowError += argsUpdating.Errors.Message;
642 if (!ContinueUpdateOnError)
643 throw argsUpdating.Errors;
645 case UpdateStatus.SkipAllRemainingRows :
647 case UpdateStatus.SkipCurrentRow :
651 throw ExceptionHelper.InvalidUpdateStatus (argsUpdating.Status);
653 command = argsUpdating.Command;
655 if (command != null) {
656 DataColumnMappingCollection columnMappings = tableMapping.ColumnMappings;
657 IDataParameter nullCheckParam = null;
658 foreach (IDataParameter parameter in command.Parameters) {
659 if ((parameter.Direction & ParameterDirection.Input) != 0) {
660 string dsColumnName = parameter.SourceColumn;
661 if (columnMappings.Contains(parameter.SourceColumn))
662 dsColumnName = columnMappings [parameter.SourceColumn].DataSetColumn;
663 if (dsColumnName == null || dsColumnName.Length <= 0) {
664 nullCheckParam = parameter;
668 DataRowVersion rowVersion = parameter.SourceVersion;
669 // Parameter version is ignored for non-update commands
670 if (statementType == StatementType.Delete)
671 rowVersion = DataRowVersion.Original;
673 parameter.Value = row [dsColumnName, rowVersion];
674 if (nullCheckParam != null && (parameter.Value != null
675 && parameter.Value != DBNull.Value)) {
676 nullCheckParam.Value = 0;
677 nullCheckParam = null;
682 } catch (Exception e) {
683 argsUpdating.Errors = e;
684 argsUpdating.Status = UpdateStatus.ErrorsOccurred;
687 IDataReader reader = null;
690 throw ExceptionHelper.UpdateRequiresCommand (commandName);
692 CommandBehavior commandBehavior = CommandBehavior.Default;
693 if (command.Connection.State == ConnectionState.Closed) {
694 command.Connection.Open ();
695 commandBehavior |= CommandBehavior.CloseConnection;
698 // use ExecuteReader because we want to use the commandbehavior parameter.
699 // so the connection will be closed if needed.
700 reader = command.ExecuteReader (commandBehavior);
702 // update the current row, if the update command returns any resultset
703 // ignore other than the first record.
704 DataColumnMappingCollection columnMappings = tableMapping.ColumnMappings;
706 if (command.UpdatedRowSource == UpdateRowSource.Both ||
707 command.UpdatedRowSource == UpdateRowSource.FirstReturnedRecord) {
709 DataTable retSchema = reader.GetSchemaTable ();
710 foreach (DataRow dr in retSchema.Rows) {
711 string columnName = dr ["ColumnName"].ToString ();
712 string dstColumnName = columnName;
713 if (columnMappings != null &&
714 columnMappings.Contains(columnName))
715 dstColumnName = columnMappings [dstColumnName].DataSetColumn;
716 DataColumn dstColumn = row.Table.Columns [dstColumnName];
717 if (dstColumn == null
718 || (dstColumn.Expression != null
719 && dstColumn.Expression.Length > 0))
721 // info from : http://www.error-bank.com/microsoft.public.dotnet.framework.windowsforms.databinding/
722 // _35_hcsyiv0dha.2328@tk2msftngp10.phx.gbl_Thread.aspx
723 // disable readonly for non-expression columns.
724 bool readOnlyState = dstColumn.ReadOnly;
725 dstColumn.ReadOnly = false;
727 row [dstColumnName] = reader [columnName];
729 dstColumn.ReadOnly = readOnlyState;
736 int tmp = reader.RecordsAffected; // records affected is valid only after closing reader
737 // if the execute does not effect any rows we throw an exception.
739 throw new DBConcurrencyException("Concurrency violation: the " +
740 commandName +"Command affected 0 records.", null,
741 new DataRow [] { row });
744 if (command.UpdatedRowSource == UpdateRowSource.Both ||
745 command.UpdatedRowSource == UpdateRowSource.OutputParameters) {
746 // Update output parameters to row values
747 foreach (IDataParameter parameter in command.Parameters) {
748 if (parameter.Direction != ParameterDirection.InputOutput
749 && parameter.Direction != ParameterDirection.Output
750 && parameter.Direction != ParameterDirection.ReturnValue)
753 string dsColumnName = parameter.SourceColumn;
754 if (columnMappings != null &&
755 columnMappings.Contains(parameter.SourceColumn))
756 dsColumnName = columnMappings [parameter.SourceColumn].DataSetColumn;
757 DataColumn dstColumn = row.Table.Columns [dsColumnName];
758 if (dstColumn == null
759 || (dstColumn.Expression != null
760 && dstColumn.Expression.Length > 0))
762 bool readOnlyState = dstColumn.ReadOnly;
763 dstColumn.ReadOnly = false;
765 row [dsColumnName] = parameter.Value;
767 dstColumn.ReadOnly = readOnlyState;
772 RowUpdatedEventArgs updatedArgs = CreateRowUpdatedEvent (row, command, statementType, tableMapping);
773 OnRowUpdated (updatedArgs);
774 switch (updatedArgs.Status) {
775 case UpdateStatus.Continue:
777 case UpdateStatus.ErrorsOccurred:
778 if (updatedArgs.Errors == null)
779 updatedArgs.Errors = ExceptionHelper.RowUpdatedError();
780 row.RowError += updatedArgs.Errors.Message;
781 if (!ContinueUpdateOnError)
782 throw updatedArgs.Errors;
784 case UpdateStatus.SkipCurrentRow:
786 case UpdateStatus.SkipAllRemainingRows:
790 if (!AcceptChangesDuringUpdate)
793 row.AcceptChanges ();
794 } catch (Exception e) {
795 row.RowError = e.Message;
796 if (!ContinueUpdateOnError)
799 if (reader != null && ! reader.IsClosed)
806 public int Update (DataSet dataSet, string srcTable)
808 MissingMappingAction mappingAction = MissingMappingAction;
810 if (mappingAction == MissingMappingAction.Ignore)
811 mappingAction = MissingMappingAction.Error;
813 DataTableMapping tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction (TableMappings, srcTable, srcTable, mappingAction);
815 DataTable dataTable = dataSet.Tables [tableMapping.DataSetTable];
816 if (dataTable == null)
817 throw new ArgumentException (String.Format ("Missing table {0}",
819 return Update (dataTable, tableMapping);
823 // All the batch methods, should be implemented, if supported,
824 // by individual providers
826 protected virtual int AddToBatch (IDbCommand command)
828 throw CreateMethodNotSupportedException ();
831 protected virtual void ClearBatch ()
833 throw CreateMethodNotSupportedException ();
836 protected virtual int ExecuteBatch ()
838 throw CreateMethodNotSupportedException ();
841 protected virtual IDataParameter GetBatchedParameter (int commandIdentifier, int parameterIndex)
843 throw CreateMethodNotSupportedException ();
846 protected virtual bool GetBatchedRecordsAffected (int commandIdentifier, out int recordsAffected, out Exception error)
853 protected virtual void InitializeBatching ()
855 throw CreateMethodNotSupportedException ();
858 protected virtual void TerminateBatching ()
860 throw CreateMethodNotSupportedException ();
863 Exception CreateMethodNotSupportedException ()
865 return new NotSupportedException ("Method is not supported.");
868 internal override void OnFillErrorInternal (FillErrorEventArgs value)
873 protected virtual void OnFillError (FillErrorEventArgs value)
875 if (FillError != null)
876 FillError (this, value);
879 #endregion // Methods