2
0

OleDbDataAdapter.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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 (null)]
  75. [DataCategory ("Update")]
  76. #if !NET_2_0
  77. [DataSysDescriptionAttribute ("Used during Update for deleted rows in DataSet.")]
  78. #endif
  79. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  80. public OleDbCommand DeleteCommand {
  81. get {
  82. return deleteCommand;
  83. }
  84. set {
  85. deleteCommand = value;
  86. }
  87. }
  88. [DefaultValue (null)]
  89. [DataCategory ("Update")]
  90. #if !NET_2_0
  91. [DataSysDescriptionAttribute ("Used during Update for new rows in DataSet.")]
  92. #endif
  93. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  94. public OleDbCommand InsertCommand {
  95. get {
  96. return insertCommand;
  97. }
  98. set {
  99. insertCommand = value;
  100. }
  101. }
  102. [DefaultValue (null)]
  103. [DataCategory ("Fill")]
  104. #if !NET_2_0
  105. [DataSysDescriptionAttribute ("Used during Fill/FillSchema.")]
  106. #endif
  107. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  108. public OleDbCommand SelectCommand {
  109. get {
  110. return selectCommand;
  111. }
  112. set {
  113. selectCommand = value;
  114. }
  115. }
  116. [DefaultValue (null)]
  117. [DataCategory ("Update")]
  118. #if !NET_2_0
  119. [DataSysDescriptionAttribute ("Used during Update for modified rows in DataSet.")]
  120. #endif
  121. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  122. public OleDbCommand UpdateCommand {
  123. get {
  124. return updateCommand;
  125. }
  126. set {
  127. updateCommand = value;
  128. }
  129. }
  130. IDbCommand IDbDataAdapter.DeleteCommand {
  131. get {
  132. return DeleteCommand;
  133. }
  134. set {
  135. if (!(value is OleDbCommand))
  136. throw new ArgumentException ();
  137. DeleteCommand = (OleDbCommand)value;
  138. }
  139. }
  140. IDbCommand IDbDataAdapter.InsertCommand {
  141. get {
  142. return InsertCommand;
  143. }
  144. set {
  145. if (!(value is OleDbCommand))
  146. throw new ArgumentException ();
  147. InsertCommand = (OleDbCommand)value;
  148. }
  149. }
  150. IDbCommand IDbDataAdapter.SelectCommand {
  151. get {
  152. return SelectCommand;
  153. }
  154. set {
  155. if (!(value is OleDbCommand))
  156. throw new ArgumentException ();
  157. SelectCommand = (OleDbCommand)value;
  158. }
  159. }
  160. MissingMappingAction IDataAdapter.MissingMappingAction {
  161. get {
  162. return missingMappingAction;
  163. }
  164. set {
  165. missingMappingAction = value;
  166. }
  167. }
  168. MissingSchemaAction IDataAdapter.MissingSchemaAction {
  169. get {
  170. return missingSchemaAction;
  171. }
  172. set {
  173. missingSchemaAction = value;
  174. }
  175. }
  176. IDbCommand IDbDataAdapter.UpdateCommand {
  177. get {
  178. return UpdateCommand;
  179. }
  180. set {
  181. if (!(value is OleDbCommand))
  182. throw new ArgumentException ();
  183. UpdateCommand = (OleDbCommand)value;
  184. }
  185. }
  186. ITableMappingCollection IDataAdapter.TableMappings {
  187. get {
  188. return TableMappings;
  189. }
  190. }
  191. #endregion // Properties
  192. #region Methods
  193. protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow,
  194. IDbCommand command,
  195. StatementType statementType,
  196. DataTableMapping tableMapping)
  197. {
  198. return new OleDbRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
  199. }
  200. protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow,
  201. IDbCommand command,
  202. StatementType statementType,
  203. DataTableMapping tableMapping)
  204. {
  205. return new OleDbRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
  206. }
  207. protected override void OnRowUpdated (RowUpdatedEventArgs value)
  208. {
  209. if (RowUpdated != null)
  210. RowUpdated (this, (OleDbRowUpdatedEventArgs) value);
  211. }
  212. protected override void OnRowUpdating (RowUpdatingEventArgs value)
  213. {
  214. if (RowUpdating != null)
  215. RowUpdating (this, (OleDbRowUpdatingEventArgs) value);
  216. }
  217. [MonoTODO]
  218. public int Fill(DataTable datatable, Object adoDBRecordSet) {
  219. throw new NotImplementedException ();
  220. }
  221. [MonoTODO]
  222. public int Fill(DataSet dataset, Object adoDBRecordSet, String srcTable) {
  223. throw new NotImplementedException ();
  224. }
  225. #endregion // Methods
  226. #region Events and Delegates
  227. #if !NET_2_0
  228. [DataSysDescription ("Event triggered before every DataRow during Update.")]
  229. #endif
  230. [DataCategory ("DataCategory_Update")]
  231. public event OleDbRowUpdatedEventHandler RowUpdated;
  232. #if !NET_2_0
  233. [DataSysDescription ("Event triggered after every DataRow during Update.")]
  234. #endif
  235. [DataCategory ("DataCategory_Update")]
  236. public event OleDbRowUpdatingEventHandler RowUpdating;
  237. #endregion // Events and Delegates
  238. [MonoTODO]
  239. protected override void Dispose (bool disposing)
  240. {
  241. base.Dispose (disposing);
  242. }
  243. }
  244. }