OleDbDataAdapter.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. //
  2. // System.Data.OleDb.OleDbDataAdapter
  3. //
  4. // Authors:
  5. // Rodrigo Moya ([email protected])
  6. // Tim Coleman ([email protected])
  7. // Konstantin Triger <[email protected]>
  8. // Boris Kirzner <[email protected]>
  9. //
  10. // Copyright (C) Rodrigo Moya, 2002
  11. // Copyright (C) Tim Coleman, 2002
  12. // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
  13. //
  14. //
  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:
  22. //
  23. // The above copyright notice and this permission notice shall be
  24. // included in all copies or substantial portions of the Software.
  25. //
  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.
  33. //
  34. using System;
  35. using System.ComponentModel;
  36. using System.Data;
  37. using System.Data.Common;
  38. namespace System.Data.OleDb
  39. {
  40. public sealed class OleDbDataAdapter : DbDataAdapter, IDbDataAdapter
  41. {
  42. #region Fields
  43. OleDbCommand deleteCommand;
  44. OleDbCommand insertCommand;
  45. OleDbCommand selectCommand;
  46. OleDbCommand updateCommand;
  47. #endregion
  48. #region Constructors
  49. public OleDbDataAdapter ()
  50. : this (new OleDbCommand ())
  51. {
  52. }
  53. public OleDbDataAdapter (OleDbCommand selectCommand)
  54. {
  55. DeleteCommand = new OleDbCommand ();
  56. InsertCommand = new OleDbCommand ();
  57. SelectCommand = selectCommand;
  58. UpdateCommand = new OleDbCommand ();
  59. }
  60. public OleDbDataAdapter (string selectCommandText, OleDbConnection selectConnection)
  61. : this (new OleDbCommand (selectCommandText, selectConnection))
  62. {
  63. }
  64. public OleDbDataAdapter (string selectCommandText, string selectConnectionString)
  65. : this (selectCommandText, new OleDbConnection (selectConnectionString))
  66. {
  67. }
  68. #endregion // Fields
  69. #region Properties
  70. public OleDbCommand DeleteCommand {
  71. get {
  72. return deleteCommand;
  73. }
  74. set {
  75. deleteCommand = value;
  76. }
  77. }
  78. public OleDbCommand InsertCommand {
  79. get {
  80. return insertCommand;
  81. }
  82. set {
  83. insertCommand = value;
  84. }
  85. }
  86. public OleDbCommand SelectCommand {
  87. get {
  88. return selectCommand;
  89. }
  90. set {
  91. selectCommand = value;
  92. }
  93. }
  94. public OleDbCommand UpdateCommand {
  95. get {
  96. return updateCommand;
  97. }
  98. set {
  99. updateCommand = value;
  100. }
  101. }
  102. IDbCommand IDbDataAdapter.DeleteCommand {
  103. get {
  104. return DeleteCommand;
  105. }
  106. set {
  107. if (value != null && !(value is OleDbCommand))
  108. throw new ArgumentException ("DeleteCommand is not of Type OleDbCommand");
  109. DeleteCommand = (OleDbCommand)value;
  110. }
  111. }
  112. IDbCommand IDbDataAdapter.InsertCommand {
  113. get {
  114. return InsertCommand;
  115. }
  116. set {
  117. if (value != null && !(value is OleDbCommand))
  118. throw new ArgumentException ("InsertCommand is not of Type OleDbCommand");
  119. InsertCommand = (OleDbCommand)value;
  120. }
  121. }
  122. IDbCommand IDbDataAdapter.SelectCommand {
  123. get {
  124. return SelectCommand;
  125. }
  126. set {
  127. if (value != null && !(value is OleDbCommand))
  128. throw new ArgumentException ("SelectCommand is not of Type OleDbCommand");
  129. SelectCommand = (OleDbCommand)value;
  130. }
  131. }
  132. IDbCommand IDbDataAdapter.UpdateCommand {
  133. get {
  134. return UpdateCommand;
  135. }
  136. set {
  137. if (value != null && !(value is OleDbCommand))
  138. throw new ArgumentException ("UpdateCommand is not of Type OleDbCommand");
  139. UpdateCommand = (OleDbCommand)value;
  140. }
  141. }
  142. ITableMappingCollection IDataAdapter.TableMappings {
  143. get {
  144. return TableMappings;
  145. }
  146. }
  147. #endregion // Properties
  148. #region Methods
  149. protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow,
  150. IDbCommand command,
  151. StatementType statementType,
  152. DataTableMapping tableMapping)
  153. {
  154. return new OleDbRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
  155. }
  156. protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow,
  157. IDbCommand command,
  158. StatementType statementType,
  159. DataTableMapping tableMapping)
  160. {
  161. return new OleDbRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
  162. }
  163. protected override void OnRowUpdated (RowUpdatedEventArgs value)
  164. {
  165. if (RowUpdated != null)
  166. RowUpdated (this, (OleDbRowUpdatedEventArgs) value);
  167. }
  168. protected override void OnRowUpdating (RowUpdatingEventArgs value)
  169. {
  170. if (RowUpdating != null)
  171. RowUpdating (this, (OleDbRowUpdatingEventArgs) value);
  172. }
  173. #endregion // Methods
  174. #region Events and Delegates
  175. public event OleDbRowUpdatedEventHandler RowUpdated;
  176. public event OleDbRowUpdatingEventHandler RowUpdating;
  177. #endregion // Events and Delegates
  178. }
  179. }