protected virtual void OnFillError(FillErrorEventArgs value) { FillErrorEventHandler handler = (FillErrorEventHandler)base.Events[EventFillError]; if (handler != null) { handler(this, value); } }
virtual protected void OnFillError(FillErrorEventArgs value) { // V1.2.3300, DbDataAdapter V1.0.3300 FillErrorEventHandler handler = (FillErrorEventHandler)Events[EventFillError]; if (null != handler) { handler(this, value); } }
/// <summary> /// Extends BeginInvoke so that when a state object is not needed, null does not need to be passed. /// <example> /// fillerroreventhandler.BeginInvoke(sender, e, callback); /// </example> /// </summary> public static IAsyncResult BeginInvoke(this FillErrorEventHandler fillerroreventhandler, Object sender, FillErrorEventArgs e, AsyncCallback callback) { if (fillerroreventhandler == null) { throw new ArgumentNullException("fillerroreventhandler"); } return(fillerroreventhandler.BeginInvoke(sender, e, callback, null)); }
internal static int FillFromReader(DataTable table, IDataReader reader, int start, int length, int [] mapping, LoadOption loadOption, FillErrorEventHandler errorHandler) { if (reader.FieldCount == 0) { return(0); } for (int i = 0; i < start; i++) { reader.Read(); } int counter = 0; object [] values = new object [mapping.Length]; while (reader.Read() && (length == 0 || counter < length)) { for (int i = 0; i < mapping.Length; i++) { values [i] = mapping [i] < 0 ? null : reader [mapping [i]]; } table.BeginLoadData(); try { table.LoadDataRow(values, loadOption); } catch (Exception e) { FillErrorEventArgs args = new FillErrorEventArgs(table, values); args.Errors = e; args.Continue = false; errorHandler(table, args); // if args.Continue is not set to true or if a handler is not set, rethrow the error.. if (!args.Continue) { throw e; } } table.EndLoadData(); counter++; } return(counter); }
public override void Load(IDataReader _IDataReader, LoadOption _LoadOption, FillErrorEventHandler _FillErrorEventHandler, params DataTable[] Tables) { HZYDataAdapter _HZYDataAdapter = new HZYDataAdapter { FillLoadOption = _LoadOption, MissingSchemaAction = MissingSchemaAction.AddWithKey }; if (_FillErrorEventHandler != null) { _HZYDataAdapter.FillError += _FillErrorEventHandler; } _HZYDataAdapter.FillFromReader(this, _IDataReader, 0, 0); if (!_IDataReader.IsClosed && !_IDataReader.NextResult()) { _IDataReader.Close(); } }
public override void Load(IDataReader reader, LoadOption loadOption, FillErrorEventHandler handler, params DataTable[] tables) { XLoadAdapter adapter = new XLoadAdapter { FillLoadOption = loadOption, MissingSchemaAction = MissingSchemaAction.AddWithKey }; if (handler != null) { adapter.FillError += handler; } adapter.FillFromReader(this, reader, 0, 0); if (!reader.IsClosed && !reader.NextResult()) { reader.Close(); } }
/// <summary> /// Fills a <see cref="T:System.Data.DataTable"/> with values from a data source using the supplied <see cref="T:System.Data.IDataReader"/> /// using an error-handling delegate. /// </summary> /// <param name="reader"> /// A <see cref="T:System.Data.IDataReader"/> that provides a result set. /// </param> /// <param name="loadOption"> /// A value from the <see cref="T:System.Data.LoadOption"/> enumeration that indicates how rows already in the /// <see cref="T:System.Data.DataTable"/> are combined with incoming rows that share the same primary key. /// </param> /// <param name="errorHandler"> /// A <see cref="T:System.Data.FillErrorEventHandler"/> delegate to call when an error occurs while loading data. /// </param> public void Load(IDataReader reader, LoadOption loadOption, FillErrorEventHandler errorHandler) { this.DataTableInstance.Load(reader, loadOption, errorHandler); }
public virtual void Load(IDataReader reader, LoadOption loadOption, FillErrorEventHandler errorHandler, params DataTable[] tables) { IntPtr ptr; Bid.ScopeEnter(out ptr, "<ds.DataSet.Load|API> reader, loadOption=%d{ds.LoadOption}", (int) loadOption); try { foreach (DataTable table in tables) { ADP.CheckArgumentNull(table, "tables"); if (table.DataSet != this) { throw ExceptionBuilder.TableNotInTheDataSet(table.TableName); } } LoadAdapter adapter = new LoadAdapter { FillLoadOption = loadOption, MissingSchemaAction = MissingSchemaAction.AddWithKey }; if (errorHandler != null) { adapter.FillError += errorHandler; } adapter.FillFromReader(tables, reader, 0, 0); if (!reader.IsClosed && !reader.NextResult()) { reader.Close(); } } finally { Bid.ScopeLeave(ref ptr); } }
public virtual void Load(IDataReader reader, LoadOption loadOption, FillErrorEventHandler errorHandler) { IntPtr ptr; Bid.ScopeEnter(out ptr, "<ds.DataTable.Load|API> %d#, loadOption=%d{ds.LoadOption}\n", this.ObjectID, (int) loadOption); try { if (this.PrimaryKey.Length == 0) { DataTableReader reader2 = reader as DataTableReader; if ((reader2 != null) && (reader2.CurrentDataTable == this)) { return; } } LoadAdapter adapter = new LoadAdapter { FillLoadOption = loadOption, MissingSchemaAction = MissingSchemaAction.AddWithKey }; if (errorHandler != null) { adapter.FillError += errorHandler; } adapter.FillFromReader(new DataTable[] { this }, reader, 0, 0); if (!reader.IsClosed && !reader.NextResult()) { reader.Close(); } } finally { Bid.ScopeLeave(ref ptr); } }
private static DataTable LoadTableFromEnumerable <T>(IEnumerable <T> source, DataTable table, LoadOption?options, FillErrorEventHandler errorHandler) where T : DataRow { if (options.HasValue) { switch (options.Value) { case LoadOption.OverwriteChanges: case LoadOption.PreserveChanges: case LoadOption.Upsert: break; default: throw DataSetUtil.InvalidLoadOption(options.Value); } } using (IEnumerator <T> rows = source.GetEnumerator()) { // need to get first row to create table if (!rows.MoveNext()) { return(table ?? throw DataSetUtil.InvalidOperation(SR.DataSetLinq_EmptyDataRowSource)); } DataRow current; if (table == null) { current = rows.Current; if (current == null) { throw DataSetUtil.InvalidOperation(SR.DataSetLinq_NullDataRow); } table = new DataTable() { Locale = CultureInfo.CurrentCulture }; // We do not copy the same properties that DataView.ToTable does. // If user needs that functionality, use other CopyToDataTable overloads. // The reasoning being, the IEnumerator<DataRow> can be sourced from // different DataTable, so we just use the "Default" instead of resolving the difference. foreach (DataColumn column in current.Table.Columns) { table.Columns.Add(column.ColumnName, column.DataType); } } table.BeginLoadData(); try { do { current = rows.Current; if (current == null) { continue; } object[] values = null; try { // 'recoverable' error block switch (current.RowState) { case DataRowState.Detached: if (!current.HasVersion(DataRowVersion.Proposed)) { throw DataSetUtil.InvalidOperation(SR.DataSetLinq_CannotLoadDetachedRow); } goto case DataRowState.Added; case DataRowState.Unchanged: case DataRowState.Added: case DataRowState.Modified: values = current.ItemArray; if (options.HasValue) { table.LoadDataRow(values, options.Value); } else { table.LoadDataRow(values, fAcceptChanges: true); } break; case DataRowState.Deleted: throw DataSetUtil.InvalidOperation(SR.DataSetLinq_CannotLoadDeletedRow); default: throw DataSetUtil.InvalidDataRowState(current.RowState); } } catch (Exception e) { if (!DataSetUtil.IsCatchableExceptionType(e)) { throw; } FillErrorEventArgs fillError = null; if (null != errorHandler) { fillError = new FillErrorEventArgs(table, values) { Errors = e }; errorHandler.Invoke(rows, fillError); } if (null == fillError) { throw; } else if (!fillError.Continue) { if (ReferenceEquals(fillError.Errors ?? e, e)) { // if user didn't change exception to throw (or set it to null) throw; } else { // user may have changed exception to throw in handler throw fillError.Errors; } } } } while (rows.MoveNext()); } finally { table.EndLoadData(); } } Debug.Assert(null != table, "null DataTable"); return(table); }
public virtual void Load(IDataReader reader, LoadOption loadOption, FillErrorEventHandler errorHandler) { long logScopeId = DataCommonEventSource.Log.EnterScope("<ds.DataTable.Load|API> {0}, loadOption={1}", ObjectID, loadOption); try { if (PrimaryKey.Length == 0) { DataTableReader dtReader = reader as DataTableReader; if (dtReader != null && dtReader.CurrentDataTable == this) { return; // if not return, it will go to infinite loop } } Common.LoadAdapter adapter = new Common.LoadAdapter(); adapter.FillLoadOption = loadOption; adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey; if (null != errorHandler) { adapter.FillError += errorHandler; } adapter.FillFromReader(new DataTable[] { this }, reader, 0, 0); if (!reader.IsClosed && !reader.NextResult()) { reader.Close(); } } finally { DataCommonEventSource.Log.ExitScope(logScopeId); } }
public static void CopyToDataTable <T> (this IEnumerable <T> source, DataTable table, LoadOption options, FillErrorEventHandler errorHandler) where T : DataRow { var reader = new RowEnumerableDataReader(source, 0); table.Load(reader, options, errorHandler); }
public virtual void Load(IDataReader reader, LoadOption loadOption, FillErrorEventHandler errorHandler, params DataTable[] tables);
/// <summary> /// Loads the contents returned by the given reader into the DataTable. /// </summary> /// <param name="table">The table to load the file contents into.</param> /// <param name="reader">The reader to use to extract the file schema and data.</param> /// <param name="loadOption">Controls how values from the flat file will be applied to existing rows.</param> /// <param name="errorHandler">A <see cref="FillErrorEventHandler"/> delegate to call when an error occurs while loading data.</param> /// <exception cref="ArgumentNullException">The table is null.</exception> /// <exception cref="ArgumentNullException">The reader is null.</exception> public static void ReadFlatFile(this DataTable table, IReader reader, LoadOption loadOption = LoadOption.PreserveChanges, FillErrorEventHandler errorHandler = null) { if (table == null) { throw new ArgumentNullException(nameof(table)); } if (reader == null) { throw new ArgumentNullException(nameof(reader)); } var fileReader = new FlatFileDataReader(reader); table.Load(fileReader, loadOption, errorHandler); }
internal static int FillFromReader (DataTable table, IDataReader reader, int start, int length, int [] mapping, LoadOption loadOption, FillErrorEventHandler errorHandler) { if (reader.FieldCount == 0) return 0 ; for (int i = 0; i < start; i++) reader.Read (); int counter = 0; object [] values = new object [mapping.Length]; while (reader.Read () && (length == 0 || counter < length)) { for (int i = 0 ; i < mapping.Length; i++) values [i] = mapping [i] < 0 ? null : reader [mapping [i]]; table.BeginLoadData (); try { table.LoadDataRow (values, loadOption); } catch (Exception e) { FillErrorEventArgs args = new FillErrorEventArgs (table, values); args.Errors = e; args.Continue = false; errorHandler (table, args); // if args.Continue is not set to true or if a handler is not set, rethrow the error.. if(!args.Continue) throw e; } table.EndLoadData (); counter++; } return counter; }
/// <summary> /// This method takes an input sequence of DataRows and produces a DataTable object /// with copies of the source rows. /// Also note that this will cause the rest of the query to execute at this point in time /// (e.g. there is no more delayed execution after this sequence operator). /// </summary> /// <param name="source">The input sequence of DataRows. CopyToDataTable uses DataRowVersion.Default when retrieving values from source DataRow /// which will include proposed values for DataRow being edited. Null DataRow in the sequence are skipped.</param> /// <param name="table">The target DataTable to load.</param> /// <param name="options">The target DataTable to load.</param> /// <param name="errorHandler">Error handler for recoverable errors. /// Recoverable errors include: /// A source DataRow is in the deleted or detached state. /// DataTable.LoadDataRow threw an exception, i.e. wrong # of columns in source row /// Unrecoverable errors include: /// exceptions from IEnumerator, DataTable.BeginLoadData or DataTable.EndLoadData</param> /// <exception cref="ArgumentNullException">if source is null</exception> /// <exception cref="ArgumentNullException">if table is null</exception> /// <exception cref="InvalidOperationException">if source DataRow is in Deleted or Detached state</exception> public static void CopyToDataTable <T>(this IEnumerable <T> source, DataTable table, LoadOption options, FillErrorEventHandler errorHandler) where T : DataRow { DataSetUtil.CheckArgumentNull(source, nameof(source)); DataSetUtil.CheckArgumentNull(table, nameof(table)); LoadTableFromEnumerable(source, table, options, errorHandler); }
public virtual void Load(IDataReader reader, LoadOption loadOption, FillErrorEventHandler errorHandler, params DataTable[] tables) { IntPtr hscp; Bid.ScopeEnter(out hscp, "<ds.DataSet.Load|API> reader, loadOption=%d{ds.LoadOption}", (int)loadOption); try { foreach (DataTable dt in tables) { Common.ADP.CheckArgumentNull(dt, "tables"); if (dt.DataSet != this) { throw ExceptionBuilder.TableNotInTheDataSet(dt.TableName); } } Common.LoadAdapter adapter = new Common.LoadAdapter(); adapter.FillLoadOption = loadOption; adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey; if (null != errorHandler) { adapter.FillError += errorHandler; } adapter.FillFromReader(tables, reader, 0, 0); if (!reader.IsClosed && !reader.NextResult()) { // reader.Close(); } } finally { Bid.ScopeLeave(ref hscp); } }
public virtual void Load (IDataReader reader, LoadOption loadOption, FillErrorEventHandler errorHandler){ IntPtr hscp; Bid.ScopeEnter(out hscp, "<ds.DataTable.Load|API> %d#, loadOption=%d{ds.LoadOption}\n", ObjectID, (int)loadOption); try { if (this.PrimaryKey.Length == 0) { DataTableReader dtReader = reader as DataTableReader; if (dtReader != null && dtReader.CurrentDataTable == this) return; // if not return, it will go to infinite loop } Common.LoadAdapter adapter = new Common.LoadAdapter(); adapter.FillLoadOption = loadOption; adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey; if (null != errorHandler) { adapter.FillError += errorHandler; } adapter.FillFromReader(new DataTable[] { this }, reader, 0, 0); if (!reader.IsClosed && !reader.NextResult()) { // reader.Close(); } } finally { Bid.ScopeLeave(ref hscp); } }
public virtual void Load(IDataReader reader, LoadOption loadOption, FillErrorEventHandler errorHandler, params DataTable[] tables) { long logScopeId = DataCommonEventSource.Log.EnterScope("<ds.DataSet.Load|API> reader, loadOption={0}", loadOption); try { foreach (DataTable dt in tables) { ADP.CheckArgumentNull(dt, nameof(tables)); if (dt.DataSet != this) { throw ExceptionBuilder.TableNotInTheDataSet(dt.TableName); } } var adapter = new LoadAdapter(); adapter.FillLoadOption = loadOption; adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey; if (null != errorHandler) { adapter.FillError += errorHandler; } adapter.FillFromReader(tables, reader, 0, 0); if (!reader.IsClosed && !reader.NextResult()) { reader.Close(); } } finally { DataCommonEventSource.Log.ExitScope(logScopeId); } }