2 // System.Data.SqlClient.SqlDataAdapter.cs
5 // Rodrigo Moya (rodrigo@ximian.com)
6 // Daniel Morgan (danmorg@sc.rr.com)
7 // Tim Coleman (tim@timcoleman.com)
8 // Veerapuram Varadhan (vvaradhan@novell.com)
10 // (C) Ximian, Inc 2002
11 // Copyright (C) 2002 Tim Coleman
13 // Copyright (C) 2004, 2009 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.
36 using System.ComponentModel;
38 using System.Data.Common;
40 namespace System.Data.SqlClient {
41 [DefaultEvent ("RowUpdated")]
42 [DesignerAttribute ("Microsoft.VSDesigner.Data.VS.SqlDataAdapterDesigner, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.IDesigner")]
43 [ToolboxItemAttribute ("Microsoft.VSDesigner.Data.VS.SqlDataAdapterToolboxItem, "+ Consts.AssemblyMicrosoft_VSDesigner)]
46 public sealed class SqlDataAdapter : DbDataAdapter, IDbDataAdapter, IDataAdapter, ICloneable
48 public sealed class SqlDataAdapter : DbDataAdapter, IDbDataAdapter
56 #if ONLY_1_0 || ONLY_1_1
57 SqlCommand _selectCommand;
58 SqlCommand _insertCommand;
59 SqlCommand _updateCommand;
60 SqlCommand _deleteCommand;
69 public SqlDataAdapter () : this ((SqlCommand) null)
73 public SqlDataAdapter (SqlCommand selectCommand)
75 SelectCommand = selectCommand;
81 public SqlDataAdapter (string selectCommandText, SqlConnection selectConnection)
82 : this (new SqlCommand (selectCommandText, selectConnection))
86 public SqlDataAdapter (string selectCommandText, string selectConnectionString)
87 : this (selectCommandText, new SqlConnection (selectConnectionString))
96 [DataSysDescription ("Used during Update for deleted rows in DataSet.")]
99 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
100 public new SqlCommand DeleteCommand {
103 return (SqlCommand)base.DeleteCommand;
105 return _deleteCommand;
110 base.DeleteCommand = value;
112 _deleteCommand = value;
118 [DataSysDescription ("Used during Update for new rows in DataSet.")]
120 [DefaultValue (null)]
121 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
122 public new SqlCommand InsertCommand {
125 return (SqlCommand)base.InsertCommand;
127 return _insertCommand;
132 base.InsertCommand = value;
134 _insertCommand = value;
140 [DataSysDescription ("Used during Fill/FillSchema.")]
142 [DefaultValue (null)]
143 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
144 public new SqlCommand SelectCommand {
147 return (SqlCommand)base.SelectCommand;
149 return _selectCommand;
154 base.SelectCommand = value;
156 _selectCommand = value;
162 [DataSysDescription ("Used during Update for modified rows in DataSet.")]
164 [DefaultValue (null)]
165 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
166 public new SqlCommand UpdateCommand {
169 return (SqlCommand)base.UpdateCommand;
171 return _updateCommand;
176 base.UpdateCommand = value;
178 _updateCommand = value;
183 IDbCommand IDbDataAdapter.SelectCommand {
184 get { return SelectCommand; }
185 set { SelectCommand = (SqlCommand) value; }
188 IDbCommand IDbDataAdapter.InsertCommand {
189 get { return InsertCommand; }
190 set { InsertCommand = (SqlCommand) value; }
193 IDbCommand IDbDataAdapter.UpdateCommand {
194 get { return UpdateCommand; }
195 set { UpdateCommand = (SqlCommand) value; }
197 IDbCommand IDbDataAdapter.DeleteCommand {
198 get { return DeleteCommand; }
199 set { DeleteCommand = (SqlCommand) value; }
203 public override int UpdateBatchSize {
204 get { return updateBatchSize; }
207 throw new ArgumentOutOfRangeException ("UpdateBatchSize");
208 updateBatchSize = value;
213 #endregion // Properties
217 protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
219 return new SqlRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
223 protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
225 return new SqlRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
229 protected override void Dispose (bool disposing)
233 // Release managed resources
235 // Release unmanaged resources
238 base.Dispose (disposing);
242 protected override void OnRowUpdated (RowUpdatedEventArgs value)
244 if (RowUpdated != null)
245 RowUpdated (this, (SqlRowUpdatedEventArgs) value);
248 protected override void OnRowUpdating (RowUpdatingEventArgs value)
250 if (RowUpdating != null)
251 RowUpdating (this, (SqlRowUpdatingEventArgs) value);
256 object ICloneable.Clone()
258 throw new NotImplementedException ();
263 // All the batch methods, should be implemented, if supported,
264 // by individual providers
267 protected override int AddToBatch (IDbCommand command)
269 throw new NotImplementedException ();
273 protected override void ClearBatch ()
275 throw new NotImplementedException ();
279 protected override int ExecuteBatch ()
281 throw new NotImplementedException ();
285 protected override IDataParameter GetBatchedParameter (int commandIdentifier, int parameterIndex)
287 throw new NotImplementedException ();
291 protected override void InitializeBatching ()
293 throw new NotImplementedException ();
297 protected override void TerminateBatching ()
299 throw new NotImplementedException ();
302 #endregion // Methods
304 #region Events and Delegates
307 [DataSysDescription ("Event triggered before every DataRow during Update.")]
309 public event SqlRowUpdatedEventHandler RowUpdated;
312 [DataSysDescription ("Event triggered after every DataRow during Update.")]
314 public event SqlRowUpdatingEventHandler RowUpdating;
316 #endregion // Events and Delegates