SqlDataAdapter.cs 5.4 KB

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