2 // System.Data.SqlClient.SqlDataAdapter.cs
\r
5 // Rodrigo Moya (rodrigo@ximian.com)
\r
6 // Daniel Morgan (danmorg@sc.rr.com)
\r
7 // Tim Coleman (tim@timcoleman.com)
\r
9 // (C) Ximian, Inc 2002
\r
10 // Copyright (C) 2002 Tim Coleman
11 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.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;
\r
38 using System.Data.Common;
\r
40 namespace System.Data.SqlClient {
\r
41 [DefaultEvent ("RowUpdated")]
\r
42 public sealed class SqlDataAdapter : DbDataAdapter, IDbDataAdapter
\r
46 bool disposed = false;
\r
47 SqlCommand deleteCommand;
\r
48 SqlCommand insertCommand;
\r
49 SqlCommand selectCommand;
\r
50 SqlCommand updateCommand;
\r
54 #region Constructors
\r
56 public SqlDataAdapter ()
\r
57 : this (new SqlCommand ())
\r
61 public SqlDataAdapter (SqlCommand selectCommand)
\r
63 DeleteCommand = null;
\r
64 InsertCommand = null;
\r
65 SelectCommand = selectCommand;
\r
66 UpdateCommand = null;
\r
69 public SqlDataAdapter (string selectCommandText, SqlConnection selectConnection)
\r
70 : this (new SqlCommand (selectCommandText, selectConnection))
\r
74 public SqlDataAdapter (string selectCommandText, string selectConnectionString)
\r
75 : this (selectCommandText, new SqlConnection (selectConnectionString))
\r
83 [DataCategory ("Update")]
\r
84 [DataSysDescription ("Used during Update for deleted rows in DataSet.")]
\r
85 [DefaultValue (null)]
\r
86 public SqlCommand DeleteCommand {
\r
87 get { return deleteCommand; }
\r
88 set { deleteCommand = value; }
\r
91 [DataCategory ("Update")]
\r
92 [DataSysDescription ("Used during Update for new rows in DataSet.")]
\r
93 [DefaultValue (null)]
\r
94 public SqlCommand InsertCommand {
\r
95 get { return insertCommand; }
\r
96 set { insertCommand = value; }
\r
99 [DataCategory ("Fill")]
\r
100 [DataSysDescription ("Used during Fill/FillSchema.")]
\r
101 [DefaultValue (null)]
\r
102 public SqlCommand SelectCommand {
\r
103 get { return selectCommand; }
\r
104 set { selectCommand = value; }
\r
107 [DataCategory ("Update")]
\r
108 [DataSysDescription ("Used during Update for modified rows in DataSet.")]
\r
109 [DefaultValue (null)]
\r
110 public SqlCommand UpdateCommand {
\r
111 get { return updateCommand; }
\r
112 set { updateCommand = value; }
\r
115 IDbCommand IDbDataAdapter.DeleteCommand {
\r
116 get { return DeleteCommand; }
\r
118 if (value != null && !(value is SqlCommand))
\r
119 throw new ArgumentException ("DeleteCommand is not of Type SqlCommand");
\r
120 DeleteCommand = (SqlCommand)value;
\r
124 IDbCommand IDbDataAdapter.InsertCommand {
\r
125 get { return InsertCommand; }
\r
127 if (value != null && !(value is SqlCommand))
\r
128 throw new ArgumentException ("InsertCommand is not of Type SqlCommand");
\r
129 InsertCommand = (SqlCommand)value;
\r
133 IDbCommand IDbDataAdapter.SelectCommand {
\r
134 get { return SelectCommand; }
\r
136 if (value != null && !(value is SqlCommand))
\r
137 throw new ArgumentException ("SelectCommand is not of Type SqlCommand");
\r
138 SelectCommand = (SqlCommand)value;
\r
142 IDbCommand IDbDataAdapter.UpdateCommand {
\r
143 get { return UpdateCommand; }
\r
145 if (value != null && !(value is SqlCommand))
\r
146 throw new ArgumentException ("UpdateCommand is not of Type SqlCommand");
\r
147 UpdateCommand = (SqlCommand)value;
\r
152 ITableMappingCollection IDataAdapter.TableMappings {
\r
153 get { return TableMappings; }
\r
156 #endregion // Properties
\r
160 protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
\r
162 return new SqlRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
\r
166 protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
\r
168 return new SqlRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
\r
171 protected override void Dispose (bool disposing)
\r
175 // Release managed resources
\r
177 // Release unmanaged resources
\r
182 protected override void OnRowUpdated (RowUpdatedEventArgs value)
\r
184 if (RowUpdated != null)
\r
185 RowUpdated (this, (SqlRowUpdatedEventArgs) value);
\r
188 protected override void OnRowUpdating (RowUpdatingEventArgs value)
\r
190 if (RowUpdating != null)
\r
191 RowUpdating (this, (SqlRowUpdatingEventArgs) value);
\r
194 #endregion // Methods
\r
196 #region Events and Delegates
\r
198 [DataCategory ("Update")]
\r
199 [DataSysDescription ("Event triggered before every DataRow during Update.")]
\r
200 public event SqlRowUpdatedEventHandler RowUpdated;
\r
202 [DataCategory ("Update")]
\r
203 [DataSysDescription ("Event triggered after every DataRow during Update.")]
\r
204 public event SqlRowUpdatingEventHandler RowUpdating;
\r
206 #endregion // Events and Delegates
\r