OleDbDataAdapter.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. //
  12. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  13. //
  14. // Permission is hereby granted, free of charge, to any person obtaining
  15. // a copy of this software and associated documentation files (the
  16. // "Software"), to deal in the Software without restriction, including
  17. // without limitation the rights to use, copy, modify, merge, publish,
  18. // distribute, sublicense, and/or sell copies of the Software, and to
  19. // permit persons to whom the Software is furnished to do so, subject to
  20. // the following conditions:
  21. //
  22. // The above copyright notice and this permission notice shall be
  23. // included in all copies or substantial portions of the Software.
  24. //
  25. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  29. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  30. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  31. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  32. //
  33. using System;
  34. using System.ComponentModel;
  35. using System.Data;
  36. using System.Data.Common;
  37. namespace System.Data.OleDb
  38. {
  39. [DefaultEvent ("RowUpdated")]
  40. [DesignerAttribute ("Microsoft.VSDesigner.Data.VS.OleDbDataAdapterDesigner, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.IDesigner")]
  41. [ToolboxItemAttribute ("Microsoft.VSDesigner.Data.VS.OleDbDataAdapterToolboxItem, "+ Consts.AssemblyMicrosoft_VSDesigner)]
  42. public sealed class OleDbDataAdapter : DbDataAdapter, IDbDataAdapter
  43. {
  44. #region Fields
  45. OleDbCommand deleteCommand;
  46. OleDbCommand insertCommand;
  47. OleDbCommand selectCommand;
  48. OleDbCommand updateCommand;
  49. MissingMappingAction missingMappingAction;
  50. MissingSchemaAction missingSchemaAction;
  51. #endregion
  52. #region Constructors
  53. public OleDbDataAdapter ()
  54. : this (new OleDbCommand ())
  55. {
  56. }
  57. public OleDbDataAdapter (OleDbCommand selectCommand)
  58. {
  59. DeleteCommand = new OleDbCommand ();
  60. InsertCommand = new OleDbCommand ();
  61. SelectCommand = selectCommand;
  62. UpdateCommand = new OleDbCommand ();
  63. }
  64. public OleDbDataAdapter (string selectCommandText, OleDbConnection selectConnection)
  65. : this (new OleDbCommand (selectCommandText, selectConnection))
  66. {
  67. }
  68. public OleDbDataAdapter (string selectCommandText, string selectConnectionString)
  69. : this (selectCommandText, new OleDbConnection (selectConnectionString))
  70. {
  71. }
  72. #endregion // Fields
  73. #region Properties
  74. [DefaultValue ("")]
  75. [DataCategory ("Update")]
  76. [DataSysDescriptionAttribute ("Used during Update for deleted rows in DataSet")]
  77. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  78. public OleDbCommand DeleteCommand {
  79. get {
  80. return deleteCommand;
  81. }
  82. set {
  83. deleteCommand = value;
  84. }
  85. }
  86. [DefaultValue ("")]
  87. [DataCategory ("Update")]
  88. [DataSysDescriptionAttribute ("Used during Update for new rows in DataSet")]
  89. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  90. public OleDbCommand InsertCommand {
  91. get {
  92. return insertCommand;
  93. }
  94. set {
  95. insertCommand = value;
  96. }
  97. }
  98. [DefaultValue ("")]
  99. [DataCategory ("Fill")]
  100. [DataSysDescriptionAttribute ("Used during Fill/FillSchema")]
  101. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  102. public OleDbCommand SelectCommand {
  103. get {
  104. return selectCommand;
  105. }
  106. set {
  107. selectCommand = value;
  108. }
  109. }
  110. [DefaultValue ("")]
  111. [DataCategory ("Update")]
  112. [DataSysDescriptionAttribute ("Used during Update for modified rows in DataSet")]
  113. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  114. public OleDbCommand UpdateCommand {
  115. get {
  116. return updateCommand;
  117. }
  118. set {
  119. updateCommand = value;
  120. }
  121. }
  122. IDbCommand IDbDataAdapter.DeleteCommand {
  123. get {
  124. return DeleteCommand;
  125. }
  126. set {
  127. if (!(value is OleDbCommand))
  128. throw new ArgumentException ();
  129. DeleteCommand = (OleDbCommand)value;
  130. }
  131. }
  132. IDbCommand IDbDataAdapter.InsertCommand {
  133. get {
  134. return InsertCommand;
  135. }
  136. set {
  137. if (!(value is OleDbCommand))
  138. throw new ArgumentException ();
  139. InsertCommand = (OleDbCommand)value;
  140. }
  141. }
  142. IDbCommand IDbDataAdapter.SelectCommand {
  143. get {
  144. return SelectCommand;
  145. }
  146. set {
  147. if (!(value is OleDbCommand))
  148. throw new ArgumentException ();
  149. SelectCommand = (OleDbCommand)value;
  150. }
  151. }
  152. MissingMappingAction IDataAdapter.MissingMappingAction {
  153. get {
  154. return missingMappingAction;
  155. }
  156. set {
  157. missingMappingAction = value;
  158. }
  159. }
  160. MissingSchemaAction IDataAdapter.MissingSchemaAction {
  161. get {
  162. return missingSchemaAction;
  163. }
  164. set {
  165. missingSchemaAction = value;
  166. }
  167. }
  168. IDbCommand IDbDataAdapter.UpdateCommand {
  169. get {
  170. return UpdateCommand;
  171. }
  172. set {
  173. if (!(value is OleDbCommand))
  174. throw new ArgumentException ();
  175. UpdateCommand = (OleDbCommand)value;
  176. }
  177. }
  178. ITableMappingCollection IDataAdapter.TableMappings {
  179. get {
  180. return TableMappings;
  181. }
  182. }
  183. #endregion // Properties
  184. #region Methods
  185. protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow,
  186. IDbCommand command,
  187. StatementType statementType,
  188. DataTableMapping tableMapping)
  189. {
  190. return new OleDbRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
  191. }
  192. protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow,
  193. IDbCommand command,
  194. StatementType statementType,
  195. DataTableMapping tableMapping)
  196. {
  197. return new OleDbRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
  198. }
  199. protected override void OnRowUpdated (RowUpdatedEventArgs value)
  200. {
  201. if (RowUpdated != null)
  202. RowUpdated (this, (OleDbRowUpdatedEventArgs) value);
  203. }
  204. protected override void OnRowUpdating (RowUpdatingEventArgs value)
  205. {
  206. if (RowUpdating != null)
  207. RowUpdating (this, (OleDbRowUpdatingEventArgs) value);
  208. }
  209. [MonoTODO]
  210. public int Fill(DataTable datatable, Object adoDBRecordSet) {
  211. throw new NotImplementedException ();
  212. }
  213. [MonoTODO]
  214. public int Fill(DataSet dataset, Object adoDBRecordSet, String srcTable) {
  215. throw new NotImplementedException ();
  216. }
  217. #endregion // Methods
  218. #region Events and Delegates
  219. [DataSysDescription ("DbDataAdapter_RowUpdated")]
  220. [DataCategory ("DataCategory_Update")]
  221. public event OleDbRowUpdatedEventHandler RowUpdated;
  222. [DataSysDescription ("DbDataAdapter_RowUpdating")]
  223. [DataCategory ("DataCategory_Update")]
  224. public event OleDbRowUpdatingEventHandler RowUpdating;
  225. #endregion // Events and Delegates
  226. [MonoTODO]
  227. protected override void Dispose (bool disposing)
  228. {
  229. base.Dispose (disposing);
  230. }
  231. }
  232. }