OleDbDataAdapter.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. #endregion
  25. #region Constructors
  26. public OleDbDataAdapter ()
  27. : this (new OleDbCommand ())
  28. {
  29. }
  30. public OleDbDataAdapter (OleDbCommand selectCommand)
  31. {
  32. DeleteCommand = new OleDbCommand ();
  33. InsertCommand = new OleDbCommand ();
  34. SelectCommand = selectCommand;
  35. UpdateCommand = new OleDbCommand ();
  36. }
  37. public OleDbDataAdapter (string selectCommandText, OleDbConnection selectConnection)
  38. : this (new OleDbCommand (selectCommandText, selectConnection))
  39. {
  40. }
  41. public OleDbDataAdapter (string selectCommandText, string selectConnectionString)
  42. : this (selectCommandText, new OleDbConnection (selectConnectionString))
  43. {
  44. }
  45. #endregion // Fields
  46. #region Properties
  47. public OleDbCommand DeleteCommand {
  48. get {
  49. return deleteCommand;
  50. }
  51. set {
  52. deleteCommand = value;
  53. }
  54. }
  55. public OleDbCommand InsertCommand {
  56. get {
  57. return insertCommand;
  58. }
  59. set {
  60. insertCommand = value;
  61. }
  62. }
  63. public OleDbCommand SelectCommand {
  64. get {
  65. return selectCommand;
  66. }
  67. set {
  68. selectCommand = value;
  69. }
  70. }
  71. public OleDbCommand UpdateCommand {
  72. get {
  73. return updateCommand;
  74. }
  75. set {
  76. updateCommand = value;
  77. }
  78. }
  79. IDbCommand IDbDataAdapter.DeleteCommand {
  80. get {
  81. return DeleteCommand;
  82. }
  83. set {
  84. if (value != null && !(value is OleDbCommand))
  85. throw new ArgumentException ("DeleteCommand is not of Type OleDbCommand");
  86. DeleteCommand = (OleDbCommand)value;
  87. }
  88. }
  89. IDbCommand IDbDataAdapter.InsertCommand {
  90. get {
  91. return InsertCommand;
  92. }
  93. set {
  94. if (value != null && !(value is OleDbCommand))
  95. throw new ArgumentException ("InsertCommand is not of Type OleDbCommand");
  96. InsertCommand = (OleDbCommand)value;
  97. }
  98. }
  99. IDbCommand IDbDataAdapter.SelectCommand {
  100. get {
  101. return SelectCommand;
  102. }
  103. set {
  104. if (value != null && !(value is OleDbCommand))
  105. throw new ArgumentException ("SelectCommand is not of Type OleDbCommand");
  106. SelectCommand = (OleDbCommand)value;
  107. }
  108. }
  109. IDbCommand IDbDataAdapter.UpdateCommand {
  110. get {
  111. return UpdateCommand;
  112. }
  113. set {
  114. if (value != null && !(value is OleDbCommand))
  115. throw new ArgumentException ("UpdateCommand is not of Type OleDbCommand");
  116. UpdateCommand = (OleDbCommand)value;
  117. }
  118. }
  119. ITableMappingCollection IDataAdapter.TableMappings {
  120. get {
  121. return TableMappings;
  122. }
  123. }
  124. #endregion // Properties
  125. #region Methods
  126. protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow,
  127. IDbCommand command,
  128. StatementType statementType,
  129. DataTableMapping tableMapping)
  130. {
  131. return new OleDbRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
  132. }
  133. protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow,
  134. IDbCommand command,
  135. StatementType statementType,
  136. DataTableMapping tableMapping)
  137. {
  138. return new OleDbRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
  139. }
  140. protected override void OnRowUpdated (RowUpdatedEventArgs value)
  141. {
  142. if (RowUpdated != null)
  143. RowUpdated (this, (OleDbRowUpdatedEventArgs) value);
  144. }
  145. protected override void OnRowUpdating (RowUpdatingEventArgs value)
  146. {
  147. if (RowUpdating != null)
  148. RowUpdating (this, (OleDbRowUpdatingEventArgs) value);
  149. }
  150. #endregion // Methods
  151. #region Events and Delegates
  152. public event OleDbRowUpdatedEventHandler RowUpdated;
  153. public event OleDbRowUpdatingEventHandler RowUpdating;
  154. #endregion // Events and Delegates
  155. }
  156. }