SqlDataAdapter.cs 4.5 KB

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