SqlDataAdapter.cs 4.3 KB

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