2 // System.Data.Common.DataAdapter
5 // Rodrigo Moya (rodrigo@ximian.com)
6 // Tim Coleman (tim@timcoleman.com)
9 // Copyright (C) Tim Coleman, 2002-2003
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System.ComponentModel;
38 namespace System.Data.Common
41 /// Represents a set of data commands and a database connection that are used to fill the DataSet and update the data source.
47 class DataAdapter : Component, IDataAdapter
51 private bool acceptChangesDuringFill;
52 private bool continueUpdateOnError;
53 private MissingMappingAction missingMappingAction;
54 private MissingSchemaAction missingSchemaAction;
55 private DataTableMappingCollection tableMappings;
58 private bool acceptChangesDuringUpdate;
59 private LoadOption fillLoadOption;
60 private bool returnProviderSpecificTypes;
67 protected DataAdapter ()
69 acceptChangesDuringFill = true;
70 continueUpdateOnError = false;
71 missingMappingAction = MissingMappingAction.Passthrough;
72 missingSchemaAction = MissingSchemaAction.Add;
73 tableMappings = new DataTableMappingCollection ();
75 acceptChangesDuringUpdate = true;
76 fillLoadOption = LoadOption.OverwriteChanges;
77 returnProviderSpecificTypes = false;
81 protected DataAdapter (DataAdapter adapter)
83 AcceptChangesDuringFill = adapter.AcceptChangesDuringFill;
84 ContinueUpdateOnError = adapter.ContinueUpdateOnError;
85 MissingMappingAction = adapter.MissingMappingAction;
86 MissingSchemaAction = adapter.MissingSchemaAction;
88 if (adapter.tableMappings != null)
89 foreach (ICloneable cloneable in adapter.TableMappings)
90 TableMappings.Add (cloneable.Clone ());
92 acceptChangesDuringUpdate = adapter.AcceptChangesDuringUpdate;
93 fillLoadOption = adapter.FillLoadOption;
94 returnProviderSpecificTypes = adapter.ReturnProviderSpecificTypes;
102 [DataCategory ("Fill")]
104 [DataSysDescription ("Whether or not Fill will call DataRow.AcceptChanges.")]
106 [DefaultValue (true)]
107 public bool AcceptChangesDuringFill {
108 get { return acceptChangesDuringFill; }
109 set { acceptChangesDuringFill = value; }
113 [DefaultValue (true)]
114 public bool AcceptChangesDuringUpdate {
115 get { return acceptChangesDuringUpdate; }
116 set { acceptChangesDuringUpdate = value; }
120 [DataCategory ("Update")]
122 [DataSysDescription ("Whether or not to continue to the next DataRow when the Update events, RowUpdating and RowUpdated, Status is UpdateStatus.ErrorsOccurred.")]
124 [DefaultValue (false)]
125 public bool ContinueUpdateOnError {
126 get { return continueUpdateOnError; }
127 set { continueUpdateOnError = value; }
131 [RefreshProperties (RefreshProperties.All)]
132 public LoadOption FillLoadOption {
133 get { return fillLoadOption; }
134 set { fillLoadOption = value; }
138 ITableMappingCollection IDataAdapter.TableMappings {
139 get { return TableMappings; }
142 [DataCategory ("Mapping")]
144 [DataSysDescription ("The action taken when a table or column in the TableMappings is missing.")]
146 [DefaultValue (MissingMappingAction.Passthrough)]
147 public MissingMappingAction MissingMappingAction {
148 get { return missingMappingAction; }
150 if (!Enum.IsDefined (typeof (MissingMappingAction), value))
151 throw ExceptionHelper.InvalidEnumValueException ("MissingMappingAction", value);
152 missingMappingAction = value;
156 [DataCategory ("Mapping")]
158 [DataSysDescription ("The action taken when a table or column in the DataSet is missing.")]
160 [DefaultValue (MissingSchemaAction.Add)]
161 public MissingSchemaAction MissingSchemaAction {
162 get { return missingSchemaAction; }
164 if (!Enum.IsDefined (typeof (MissingSchemaAction), value))
165 throw ExceptionHelper.InvalidEnumValueException ("MissingSchemaAction", value);
166 missingSchemaAction = value;
171 [DefaultValue (false)]
172 public virtual bool ReturnProviderSpecificTypes {
173 get { return returnProviderSpecificTypes; }
174 set { returnProviderSpecificTypes = value; }
178 [DataCategory ("Mapping")]
180 [DataSysDescription ("How to map source table to DataSet table.")]
182 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
183 public DataTableMappingCollection TableMappings {
184 get { return tableMappings; }
192 public event FillErrorEventHandler FillError;
200 [Obsolete ("Use the protected constructor instead", false)]
203 protected virtual DataAdapter CloneInternals ()
205 throw new NotImplementedException ();
208 protected virtual DataTableMappingCollection CreateTableMappings ()
210 return new DataTableMappingCollection ();
214 protected override void Dispose (bool disposing)
216 throw new NotImplementedException ();
219 protected virtual bool ShouldSerializeTableMappings ()
226 public virtual int Fill (DataSet dataSet)
228 throw new NotSupportedException ();
231 protected virtual int Fill (DataTable dataTable, IDataReader dataReader)
233 throw new NotImplementedException ();
237 protected virtual int Fill (DataTable[] dataTables, IDataReader dataReader, int startRecord, int maxRecords)
239 throw new NotImplementedException ();
243 protected virtual int Fill (DataSet dataSet, string srcTable, IDataReader dataReader, int startRecord, int maxRecords)
245 throw new NotImplementedException ();
249 protected virtual DataTable FillSchema (DataTable dataTable, SchemaType schemaType, IDataReader dataReader)
251 throw new NotImplementedException ();
255 protected virtual DataTable[] FillSchema (DataSet dataSet, SchemaType schemaType, string srcTable, IDataReader dataReader)
257 throw new NotImplementedException ();
260 public virtual DataTable[] FillSchema (DataSet dataSet, SchemaType schemaType)
262 throw new NotSupportedException ();
266 [EditorBrowsable (EditorBrowsableState.Advanced)]
267 public virtual IDataParameter[] GetFillParameters ()
269 throw new NotImplementedException ();
273 protected bool HasTableMappings ()
275 return (TableMappings.Count != 0);
278 protected virtual void OnFillError (FillErrorEventArgs value)
280 if (FillError != null)
281 FillError (this, value);
286 [EditorBrowsable (EditorBrowsableState.Never)]
287 public void ResetFillLoadOption ()
290 FillLoadOption = LoadOption.OverwriteChanges;
293 [EditorBrowsable (EditorBrowsableState.Never)]
294 public virtual bool ShouldSerializeAcceptChangesDuringFill ()
299 [EditorBrowsable (EditorBrowsableState.Never)]
300 public virtual bool ShouldSerializeFillLoadOption ()
306 public virtual int Update (DataSet dataSet)
308 throw new NotImplementedException ();
311 public abstract int Fill (DataSet dataSet);
312 public abstract DataTable[] FillSchema (DataSet dataSet, SchemaType schemaType);
313 public abstract IDataParameter[] GetFillParameters ();
314 public abstract int Update (DataSet dataSet);