2
0

SqlDataAdapter.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. //
  2. // System.Data.SqlClient.SqlDataAdapter.cs
  3. //
  4. // Author:
  5. // Rodrigo Moya ([email protected])
  6. // Daniel Morgan ([email protected])
  7. // Tim Coleman ([email protected])
  8. //
  9. // (C) Ximian, Inc 2002
  10. // Copyright (C) 2002 Tim Coleman
  11. //
  12. using System;
  13. using System.ComponentModel;
  14. using System.Data;
  15. using System.Data.Common;
  16. namespace System.Data.SqlClient {
  17. [DefaultEvent ("RowUpdated")]
  18. [DesignerAttribute ("Microsoft.VSDesigner.Data.VS.SqlDataAdapterDesigner, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.IDesigner")]
  19. [ToolboxItemAttribute ("Microsoft.VSDesigner.Data.VS.SqlDataAdapterToolboxItem, "+ Consts.AssemblyMicrosoft_VSDesigner)]
  20. public sealed class SqlDataAdapter : DbDataAdapter, IDbDataAdapter
  21. {
  22. #region Fields
  23. bool disposed = false;
  24. SqlCommand deleteCommand;
  25. SqlCommand insertCommand;
  26. SqlCommand selectCommand;
  27. SqlCommand updateCommand;
  28. #endregion
  29. #region Constructors
  30. public SqlDataAdapter ()
  31. : this (new SqlCommand ())
  32. {
  33. }
  34. public SqlDataAdapter (SqlCommand selectCommand)
  35. {
  36. DeleteCommand = null;
  37. InsertCommand = null;
  38. SelectCommand = selectCommand;
  39. UpdateCommand = null;
  40. }
  41. public SqlDataAdapter (string selectCommandText, SqlConnection selectConnection)
  42. : this (new SqlCommand (selectCommandText, selectConnection))
  43. {
  44. }
  45. public SqlDataAdapter (string selectCommandText, string selectConnectionString)
  46. : this (selectCommandText, new SqlConnection (selectConnectionString))
  47. {
  48. }
  49. #endregion
  50. #region Properties
  51. [DataCategory ("Update")]
  52. [DataSysDescription ("Used during Update for deleted rows in DataSet.")]
  53. [DefaultValue (null)]
  54. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  55. public SqlCommand DeleteCommand {
  56. get { return deleteCommand; }
  57. set { deleteCommand = value; }
  58. }
  59. [DataCategory ("Update")]
  60. [DataSysDescription ("Used during Update for new rows in DataSet.")]
  61. [DefaultValue (null)]
  62. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  63. public SqlCommand InsertCommand {
  64. get { return insertCommand; }
  65. set { insertCommand = value; }
  66. }
  67. [DataCategory ("Fill")]
  68. [DataSysDescription ("Used during Fill/FillSchema.")]
  69. [DefaultValue (null)]
  70. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  71. public SqlCommand SelectCommand {
  72. get { return selectCommand; }
  73. set { selectCommand = value; }
  74. }
  75. [DataCategory ("Update")]
  76. [DataSysDescription ("Used during Update for modified rows in DataSet.")]
  77. [DefaultValue (null)]
  78. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  79. public SqlCommand UpdateCommand {
  80. get { return updateCommand; }
  81. set { updateCommand = value; }
  82. }
  83. IDbCommand IDbDataAdapter.DeleteCommand {
  84. get { return DeleteCommand; }
  85. set {
  86. if (!(value is SqlCommand))
  87. throw new ArgumentException ();
  88. DeleteCommand = (SqlCommand)value;
  89. }
  90. }
  91. IDbCommand IDbDataAdapter.InsertCommand {
  92. get { return InsertCommand; }
  93. set {
  94. if (!(value is SqlCommand))
  95. throw new ArgumentException ();
  96. InsertCommand = (SqlCommand)value;
  97. }
  98. }
  99. IDbCommand IDbDataAdapter.SelectCommand {
  100. get { return SelectCommand; }
  101. set {
  102. if (!(value is SqlCommand))
  103. throw new ArgumentException ();
  104. SelectCommand = (SqlCommand)value;
  105. }
  106. }
  107. IDbCommand IDbDataAdapter.UpdateCommand {
  108. get { return UpdateCommand; }
  109. set {
  110. if (!(value is SqlCommand))
  111. throw new ArgumentException ();
  112. UpdateCommand = (SqlCommand)value;
  113. }
  114. }
  115. ITableMappingCollection IDataAdapter.TableMappings {
  116. get { return TableMappings; }
  117. }
  118. #endregion // Properties
  119. #region Methods
  120. protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
  121. {
  122. return new SqlRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
  123. }
  124. protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
  125. {
  126. return new SqlRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
  127. }
  128. protected override void Dispose (bool disposing)
  129. {
  130. if (!disposed) {
  131. if (disposing) {
  132. // Release managed resources
  133. }
  134. // Release unmanaged resources
  135. disposed = true;
  136. }
  137. }
  138. protected override void OnRowUpdated (RowUpdatedEventArgs value)
  139. {
  140. if (RowUpdated != null)
  141. RowUpdated (this, (SqlRowUpdatedEventArgs) value);
  142. }
  143. protected override void OnRowUpdating (RowUpdatingEventArgs value)
  144. {
  145. if (RowUpdating != null)
  146. RowUpdating (this, (SqlRowUpdatingEventArgs) value);
  147. }
  148. #endregion // Methods
  149. #region Events and Delegates
  150. [DataCategory ("Update")]
  151. [DataSysDescription ("Event triggered before every DataRow during Update.")]
  152. public event SqlRowUpdatedEventHandler RowUpdated;
  153. [DataCategory ("Update")]
  154. [DataSysDescription ("Event triggered after every DataRow during Update.")]
  155. public event SqlRowUpdatingEventHandler RowUpdating;
  156. #endregion // Events and Delegates
  157. }
  158. }