OleDbDataAdapter.cs 4.2 KB

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