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)
9 // (C) Ximian, Inc 2002
10 // Copyright (C) 2002 Tim Coleman
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.ComponentModel;
39 using System.Data.Common;
41 namespace System.Data.SqlClient {
42 [DefaultEvent ("RowUpdated")]
43 [DesignerAttribute ("Microsoft.VSDesigner.Data.VS.SqlDataAdapterDesigner, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.IDesigner")]
44 [ToolboxItemAttribute ("Microsoft.VSDesigner.Data.VS.SqlDataAdapterToolboxItem, "+ Consts.AssemblyMicrosoft_VSDesigner)]
45 public sealed class SqlDataAdapter : DbDataAdapter, IDbDataAdapter
49 bool disposed = false;
50 SqlCommand deleteCommand;
51 SqlCommand insertCommand;
52 SqlCommand selectCommand;
53 SqlCommand updateCommand;
59 public SqlDataAdapter ()
60 : this (new SqlCommand ())
64 public SqlDataAdapter (SqlCommand selectCommand)
68 SelectCommand = selectCommand;
72 public SqlDataAdapter (string selectCommandText, SqlConnection selectConnection)
73 : this (new SqlCommand (selectCommandText, selectConnection))
77 public SqlDataAdapter (string selectCommandText, string selectConnectionString)
78 : this (selectCommandText, new SqlConnection (selectConnectionString))
86 [DataCategory ("Update")]
88 [DataSysDescription ("Used during Update for deleted rows in DataSet.")]
91 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
92 public new SqlCommand DeleteCommand {
93 get { return deleteCommand; }
94 set { deleteCommand = value; }
97 [DataCategory ("Update")]
99 [DataSysDescription ("Used during Update for new rows in DataSet.")]
101 [DefaultValue (null)]
102 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
103 public new SqlCommand InsertCommand {
104 get { return insertCommand; }
105 set { insertCommand = value; }
108 [DataCategory ("Fill")]
110 [DataSysDescription ("Used during Fill/FillSchema.")]
112 [DefaultValue (null)]
113 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
114 public new SqlCommand SelectCommand {
115 get { return selectCommand; }
116 set { selectCommand = value; }
119 [DataCategory ("Update")]
121 [DataSysDescription ("Used during Update for modified rows in DataSet.")]
123 [DefaultValue (null)]
124 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
125 public new SqlCommand UpdateCommand {
126 get { return updateCommand; }
127 set { updateCommand = value; }
130 IDbCommand IDbDataAdapter.DeleteCommand {
131 get { return DeleteCommand; }
133 if (!(value is SqlCommand))
134 throw new ArgumentException ();
135 DeleteCommand = (SqlCommand)value;
139 IDbCommand IDbDataAdapter.InsertCommand {
140 get { return InsertCommand; }
142 if (!(value is SqlCommand))
143 throw new ArgumentException ();
144 InsertCommand = (SqlCommand)value;
148 IDbCommand IDbDataAdapter.SelectCommand {
149 get { return SelectCommand; }
151 if (!(value is SqlCommand))
152 throw new ArgumentException ();
153 SelectCommand = (SqlCommand)value;
157 IDbCommand IDbDataAdapter.UpdateCommand {
158 get { return UpdateCommand; }
160 if (!(value is SqlCommand))
161 throw new ArgumentException ();
162 UpdateCommand = (SqlCommand)value;
167 ITableMappingCollection IDataAdapter.TableMappings {
168 get { return TableMappings; }
171 #endregion // Properties
175 protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
177 return new SqlRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
181 protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
183 return new SqlRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
186 protected override void Dispose (bool disposing)
190 // Release managed resources
192 // Release unmanaged resources
197 protected override void OnRowUpdated (RowUpdatedEventArgs value)
199 if (RowUpdated != null)
200 RowUpdated (this, (SqlRowUpdatedEventArgs) value);
203 protected override void OnRowUpdating (RowUpdatingEventArgs value)
205 if (RowUpdating != null)
206 RowUpdating (this, (SqlRowUpdatingEventArgs) value);
209 #endregion // Methods
211 #region Events and Delegates
213 [DataCategory ("Update")]
215 [DataSysDescription ("Event triggered before every DataRow during Update.")]
217 public event SqlRowUpdatedEventHandler RowUpdated;
219 [DataCategory ("Update")]
221 [DataSysDescription ("Event triggered after every DataRow during Update.")]
223 public event SqlRowUpdatingEventHandler RowUpdating;
225 #endregion // Events and Delegates