2 // Mono.Data.TdsClient.TdsDataAdapter.cs
5 // Tim Coleman (tim@timcoleman.com)
7 // Copyright (C) Tim Coleman, 2002
11 using System.ComponentModel;
13 using System.Data.Common;
15 namespace Mono.Data.TdsClient
18 /// Represents a set of command-related properties that are used
19 /// to fill the DataSet and update a data source, all this
20 /// from a SQL database.
22 public sealed class TdsDataAdapter : DbDataAdapter, IDbDataAdapter
26 TdsCommand deleteCommand;
27 TdsCommand insertCommand;
28 TdsCommand selectCommand;
29 TdsCommand updateCommand;
31 static readonly object EventRowUpdated = new object();
32 static readonly object EventRowUpdating = new object();
38 public TdsDataAdapter ()
39 : this (new TdsCommand ())
43 public TdsDataAdapter (TdsCommand selectCommand)
45 DeleteCommand = new TdsCommand ();
46 InsertCommand = new TdsCommand ();
47 SelectCommand = selectCommand;
48 UpdateCommand = new TdsCommand ();
51 public TdsDataAdapter (string selectCommandText, TdsConnection selectConnection)
52 : this (new TdsCommand (selectCommandText, selectConnection))
56 public TdsDataAdapter (string selectCommandText, string selectConnectionString)
57 : this (selectCommandText, new TdsConnection (selectConnectionString))
65 public TdsCommand DeleteCommand {
66 get { return deleteCommand; }
67 set { deleteCommand = value; }
70 public TdsCommand InsertCommand {
71 get { return insertCommand; }
72 set { insertCommand = value; }
75 public TdsCommand SelectCommand {
76 get { return selectCommand; }
77 set { selectCommand = value; }
80 public TdsCommand UpdateCommand {
81 get { return updateCommand; }
82 set { updateCommand = value; }
85 IDbCommand IDbDataAdapter.DeleteCommand {
86 get { return DeleteCommand; }
88 if (!(value is TdsCommand))
89 throw new ArgumentException ();
90 DeleteCommand = (TdsCommand)value;
94 IDbCommand IDbDataAdapter.InsertCommand {
95 get { return InsertCommand; }
97 if (!(value is TdsCommand))
98 throw new ArgumentException ();
99 InsertCommand = (TdsCommand)value;
103 IDbCommand IDbDataAdapter.SelectCommand {
104 get { return SelectCommand; }
106 if (!(value is TdsCommand))
107 throw new ArgumentException ();
108 SelectCommand = (TdsCommand)value;
112 IDbCommand IDbDataAdapter.UpdateCommand {
113 get { return UpdateCommand; }
115 if (!(value is TdsCommand))
116 throw new ArgumentException ();
117 UpdateCommand = (TdsCommand)value;
122 ITableMappingCollection IDataAdapter.TableMappings {
123 get { return TableMappings; }
126 #endregion // Properties
130 protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
132 return new TdsRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
136 protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
138 return new TdsRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
141 protected override void OnRowUpdated (RowUpdatedEventArgs value)
143 TdsRowUpdatedEventHandler handler = (TdsRowUpdatedEventHandler) Events[EventRowUpdated];
144 if ((handler != null) && (value is TdsRowUpdatedEventArgs))
145 handler (this, (TdsRowUpdatedEventArgs) value);
148 protected override void OnRowUpdating (RowUpdatingEventArgs value)
150 TdsRowUpdatingEventHandler handler = (TdsRowUpdatingEventHandler) Events[EventRowUpdating];
151 if ((handler != null) && (value is TdsRowUpdatingEventArgs))
152 handler (this, (TdsRowUpdatingEventArgs) value);
155 #endregion // Methods
157 #region Events and Delegates
159 public event TdsRowUpdatedEventHandler RowUpdated {
160 add { Events.AddHandler (EventRowUpdated, value); }
161 remove { Events.RemoveHandler (EventRowUpdated, value); }
164 public event TdsRowUpdatingEventHandler RowUpdating {
165 add { Events.AddHandler (EventRowUpdating, value); }
166 remove { Events.RemoveHandler (EventRowUpdating, value); }
169 #endregion // Events and Delegates