SqlDataSourceView.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. //
  2. // System.Web.UI.WebControls.SqlDataSourceView
  3. //
  4. // Authors:
  5. // Ben Maurer ([email protected])
  6. // Sanjay Gupta ([email protected])
  7. //
  8. // (C) 2003 Ben Maurer
  9. // (C) Novell, Inc. (http://www.novell.com)
  10. //
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. #if NET_2_0
  32. using System.Collections;
  33. using System.Collections.Specialized;
  34. using System.Text;
  35. using System.Data;
  36. using System.ComponentModel;
  37. using System.Data.Common;
  38. namespace System.Web.UI.WebControls {
  39. public class SqlDataSourceView : DataSourceView, IStateManager {
  40. HttpContext context;
  41. DbProviderFactory factory;
  42. DbConnection connection;
  43. public SqlDataSourceView (SqlDataSource owner, string name, HttpContext context)
  44. : base (owner, name)
  45. {
  46. this.owner = owner;
  47. this.name = name;
  48. this.context = context;
  49. }
  50. void InitConnection ()
  51. {
  52. if (factory == null) factory = owner.GetDbProviderFactoryInternal ();
  53. if (connection == null) {
  54. connection = factory.CreateConnection();
  55. connection.ConnectionString = owner.ConnectionString;
  56. }
  57. }
  58. public int Delete (IDictionary keys, IDictionary oldValues)
  59. {
  60. return ExecuteDelete (keys, oldValues);
  61. }
  62. [MonoTODO ("Handle keys, oldValues, parameters and check for path for AccessDBFile")]
  63. protected override int ExecuteDelete (IDictionary keys, IDictionary oldValues)
  64. {
  65. if (!CanDelete)
  66. throw new NotSupportedException("Delete operation is not supported");
  67. if (oldValues == null && conflictOptions == ConflictOptions.CompareAllValues)
  68. throw new InvalidOperationException ("oldValues parameters should be specified when ConflictOptions is set to CompareAllValues");
  69. InitConnection ();
  70. DbCommand command = factory.CreateCommand ();
  71. command.CommandText = DeleteCommand;
  72. command.Connection = connection;
  73. command.CommandType = CommandType.Text;
  74. if (DeleteParameters.Count > 0)
  75. InitializeParameters (command, DeleteParameters, null);
  76. OnDeleting (new SqlDataSourceCommandEventArgs (command));
  77. bool closed = connection.State == ConnectionState.Closed;
  78. if (closed)
  79. connection.Open();
  80. Exception exception = null;
  81. int result = -1;;
  82. try {
  83. result = command.ExecuteNonQuery();
  84. } catch (Exception e) {
  85. exception = e;
  86. }
  87. if (closed)
  88. connection.Close ();
  89. OnDeleted (new SqlDataSourceStatusEventArgs (command, result, exception));
  90. if (exception != null)
  91. throw exception;
  92. return result;
  93. }
  94. public int Insert (IDictionary values)
  95. {
  96. return Insert (values);
  97. }
  98. [MonoTODO ("Handle values and parameters")]
  99. protected override int ExecuteInsert (IDictionary values)
  100. {
  101. if (!CanInsert)
  102. throw new NotSupportedException ("Insert operation is not supported");
  103. InitConnection ();
  104. DbCommand command = factory.CreateCommand ();
  105. command.CommandText = InsertCommand;
  106. command.Connection = connection;
  107. command.CommandType = CommandType.Text;
  108. if (InsertParameters.Count > 0)
  109. InitializeParameters (command, InsertParameters, null);
  110. OnInserting (new SqlDataSourceCommandEventArgs (command));
  111. bool closed = connection.State == ConnectionState.Closed;
  112. if (closed)
  113. connection.Open();
  114. Exception exception = null;
  115. int result = -1;
  116. try {
  117. result = command.ExecuteNonQuery();
  118. } catch (Exception e) {
  119. exception = e;
  120. }
  121. if (closed)
  122. connection.Close ();
  123. OnInserted (new SqlDataSourceStatusEventArgs (command, result, exception));
  124. if (exception != null)
  125. throw exception;
  126. return result;
  127. }
  128. public IEnumerable Select (DataSourceSelectArguments arguments)
  129. {
  130. return ExecuteSelect (arguments);
  131. }
  132. [MonoTODO ("Handle @arguments")]
  133. protected internal override IEnumerable ExecuteSelect (DataSourceSelectArguments arguments)
  134. {
  135. InitConnection ();
  136. DbCommand command = factory.CreateCommand ();
  137. command.CommandText = SelectCommand;
  138. command.Connection = connection;
  139. command.CommandType = CommandType.Text;
  140. if (SelectParameters.Count > 0)
  141. InitializeParameters (command, SelectParameters, null);
  142. OnSelecting (new SqlDataSourceSelectingEventArgs (command, arguments));
  143. if (owner.DataSourceMode == SqlDataSourceMode.DataSet) {
  144. DbDataAdapter adapter = factory.CreateDataAdapter ();
  145. adapter.SelectCommand = command;
  146. DataSet dataset = new DataSet ();
  147. adapter.Fill (dataset, name);
  148. return dataset.CreateDataReader ();
  149. }
  150. else {
  151. bool closed = connection.State == ConnectionState.Closed;
  152. if (closed)
  153. connection.Open ();
  154. return command.ExecuteReader (closed ? CommandBehavior.CloseConnection : CommandBehavior.Default);
  155. }
  156. }
  157. public int Update (IDictionary keys, IDictionary values, IDictionary oldValues)
  158. {
  159. return ExecuteUpdate (keys, values, oldValues);
  160. }
  161. [MonoTODO ("Handle keys, values and oldValues")]
  162. protected override int ExecuteUpdate (IDictionary keys, IDictionary values, IDictionary oldValues)
  163. {
  164. if (!CanUpdate)
  165. throw new NotSupportedException ("Update operation is not supported");
  166. if (oldValues == null && conflictOptions == ConflictOptions.CompareAllValues)
  167. throw new InvalidOperationException ("oldValues parameters should be specified when ConflictOptions is set to CompareAllValues");
  168. InitConnection ();
  169. DbCommand command = factory.CreateCommand ();
  170. command.CommandText = UpdateCommand;
  171. command.Connection = connection;
  172. command.CommandType = CommandType.Text;
  173. if (UpdateParameters.Count > 0)
  174. InitializeParameters (command, UpdateParameters, null);
  175. OnUpdating (new SqlDataSourceCommandEventArgs (command));
  176. bool closed = connection.State == ConnectionState.Closed;
  177. if (closed)
  178. connection.Open();
  179. Exception exception = null;
  180. int result = -1;
  181. try {
  182. result = command.ExecuteNonQuery ();
  183. }catch (Exception e) {
  184. exception = e;
  185. }
  186. if (closed)
  187. connection.Close ();
  188. OnUpdated (new SqlDataSourceStatusEventArgs (command, result, exception));
  189. if (exception != null)
  190. throw exception;
  191. return result;
  192. }
  193. void InitializeParameters (DbCommand command, ParameterCollection parameters, IDictionary exclusionList)
  194. {
  195. IOrderedDictionary values = parameters.GetValues (HttpContext.Current, owner);
  196. foreach (Parameter p in parameters) {
  197. DbParameter dbp = factory.CreateParameter ();
  198. dbp.ParameterName = p.Name;
  199. dbp.Value = values[p.Name];
  200. dbp.Direction = p.Direction;
  201. dbp.Size = p.Size;
  202. command.Parameters.Add (dbp);
  203. }
  204. }
  205. void IStateManager.LoadViewState (object savedState)
  206. {
  207. LoadViewState (savedState);
  208. }
  209. object IStateManager.SaveViewState ()
  210. {
  211. return SaveViewState ();
  212. }
  213. void IStateManager.TrackViewState ()
  214. {
  215. TrackViewState ();
  216. }
  217. protected virtual void LoadViewState (object savedState)
  218. {
  219. object [] vs = savedState as object [];
  220. if (vs == null)
  221. return;
  222. if (vs [0] != null) ((IStateManager) deleteParameters).LoadViewState (vs [0]);
  223. if (vs [1] != null) ((IStateManager) filterParameters).LoadViewState (vs [1]);
  224. if (vs [2] != null) ((IStateManager) insertParameters).LoadViewState (vs [2]);
  225. if (vs [3] != null) ((IStateManager) selectParameters).LoadViewState (vs [3]);
  226. if (vs [4] != null) ((IStateManager) updateParameters).LoadViewState (vs [4]);
  227. if (vs [5] != null) ((IStateManager) ViewState).LoadViewState (vs [5]);
  228. }
  229. protected virtual object SaveViewState ()
  230. {
  231. object [] vs = new object [6];
  232. if (deleteParameters != null) vs [0] = ((IStateManager) deleteParameters).SaveViewState ();
  233. if (filterParameters != null) vs [1] = ((IStateManager) filterParameters).SaveViewState ();
  234. if (insertParameters != null) vs [2] = ((IStateManager) insertParameters).SaveViewState ();
  235. if (selectParameters != null) vs [3] = ((IStateManager) selectParameters).SaveViewState ();
  236. if (updateParameters != null) vs [4] = ((IStateManager) updateParameters).SaveViewState ();
  237. if (viewState != null) vs [5] = ((IStateManager) viewState).SaveViewState ();
  238. foreach (object o in vs)
  239. if (o != null) return vs;
  240. return null;
  241. }
  242. protected virtual void TrackViewState ()
  243. {
  244. tracking = true;
  245. if (deleteParameters != null) ((IStateManager) deleteParameters).TrackViewState ();
  246. if (filterParameters != null) ((IStateManager) filterParameters).TrackViewState ();
  247. if (insertParameters != null) ((IStateManager) insertParameters).TrackViewState ();
  248. if (selectParameters != null) ((IStateManager) selectParameters).TrackViewState ();
  249. if (updateParameters != null) ((IStateManager) updateParameters).TrackViewState ();
  250. if (viewState != null) ((IStateManager) viewState).TrackViewState ();
  251. }
  252. bool IStateManager.IsTrackingViewState {
  253. get { return IsTrackingViewState; }
  254. }
  255. bool cancelSelectOnNullParameter = true;
  256. public bool CancelSelectOnNullParameter {
  257. get { return cancelSelectOnNullParameter; }
  258. set { cancelSelectOnNullParameter = value; }
  259. }
  260. public override bool CanDelete {
  261. get { return DeleteCommand != null && DeleteCommand != ""; }
  262. }
  263. public override bool CanInsert {
  264. get { return InsertCommand != null && InsertCommand != ""; }
  265. }
  266. public override bool CanPage {
  267. /* according to MS, this is false in all cases */
  268. get { return false; }
  269. }
  270. public override bool CanRetrieveTotalRowCount {
  271. /* according to MS, this is false in all cases */
  272. get { return false; }
  273. }
  274. public override bool CanSort {
  275. get {
  276. /* we can sort if we're a DataSet, regardless of sort parameter name.
  277. we can sort if we're a DataReader, if the sort parameter name is not null/"".
  278. */
  279. return (owner.DataSourceMode == SqlDataSourceMode.DataSet
  280. || (SortParameterName != null && SortParameterName != ""));
  281. }
  282. }
  283. public override bool CanUpdate {
  284. get { return UpdateCommand != null && UpdateCommand != ""; }
  285. }
  286. ConflictOptions conflictOptions = ConflictOptions.OverwriteChanges;
  287. public ConflictOptions ConflictDetection {
  288. get { return conflictOptions; }
  289. set { conflictOptions = value; }
  290. }
  291. public string DeleteCommand {
  292. get { return ViewState.GetString ("DeleteCommand", ""); }
  293. set { ViewState ["DeleteCommand"] = value; }
  294. }
  295. [MonoTODO]
  296. public SqlDataSourceCommandType DeleteCommandType {
  297. get { return (SqlDataSourceCommandType) ViewState.GetInt ("DeleteCommandType", (int)SqlDataSourceCommandType.StoredProcedure); }
  298. set { ViewState ["DeleteCommandType"] = value; }
  299. }
  300. [DefaultValueAttribute (null)]
  301. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  302. [EditorAttribute ("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  303. public ParameterCollection DeleteParameters {
  304. get { return GetParameterCollection (ref deleteParameters); }
  305. }
  306. public string FilterExpression {
  307. get { return ViewState.GetString ("FilterExpression", ""); }
  308. set { ViewState ["FilterExpression"] = value; }
  309. }
  310. [EditorAttribute ("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  311. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  312. [DefaultValueAttribute (null)]
  313. public ParameterCollection FilterParameters {
  314. get { return GetParameterCollection (ref filterParameters); }
  315. }
  316. public string InsertCommand {
  317. get { return ViewState.GetString ("InsertCommand", ""); }
  318. set { ViewState ["InsertCommand"] = value; }
  319. }
  320. [MonoTODO]
  321. public SqlDataSourceCommandType InsertCommandType {
  322. get { return (SqlDataSourceCommandType) ViewState.GetInt ("InsertCommandType", (int)SqlDataSourceCommandType.StoredProcedure); }
  323. set { ViewState ["InsertCommandType"] = value; }
  324. }
  325. [EditorAttribute ("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  326. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  327. [DefaultValueAttribute (null)]
  328. public ParameterCollection InsertParameters {
  329. get { return GetParameterCollection (ref insertParameters); }
  330. }
  331. protected bool IsTrackingViewState {
  332. get { return tracking; }
  333. }
  334. [MonoTODO]
  335. [DefaultValue ("{0}")]
  336. public string OldValuesParameterFormatString {
  337. get { return ViewState.GetString ("OldValuesParameterFormatString", "{0}"); }
  338. set { ViewState ["OldValuesParameterFormatString"] = value; }
  339. }
  340. public string SelectCommand {
  341. get { return ViewState.GetString ("SelectCommand", ""); }
  342. set { ViewState ["SelectCommand"] = value; }
  343. }
  344. [MonoTODO]
  345. public SqlDataSourceCommandType SelectCommandType {
  346. get { return (SqlDataSourceCommandType) ViewState.GetInt ("SelectCommandType", (int)SqlDataSourceCommandType.StoredProcedure); }
  347. set { ViewState ["SelectCommandType"] = value; }
  348. }
  349. public ParameterCollection SelectParameters {
  350. get { return GetParameterCollection (ref selectParameters); }
  351. }
  352. [MonoTODO]
  353. public string SortParameterName {
  354. get { return ViewState.GetString ("SortParameterName", ""); }
  355. set { ViewState ["SortParameterName"] = value; }
  356. }
  357. public string UpdateCommand {
  358. get { return ViewState.GetString ("UpdateCommand", ""); }
  359. set { ViewState ["UpdateCommand"] = value; }
  360. }
  361. [MonoTODO]
  362. public SqlDataSourceCommandType UpdateCommandType {
  363. get { return (SqlDataSourceCommandType) ViewState.GetInt ("UpdateCommandType", (int)SqlDataSourceCommandType.StoredProcedure); }
  364. set { ViewState ["UpdateCommandType"] = value; }
  365. }
  366. [EditorAttribute ("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  367. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  368. [DefaultValueAttribute (null)]
  369. public ParameterCollection UpdateParameters {
  370. get { return GetParameterCollection (ref updateParameters); }
  371. }
  372. void ParametersChanged (object source, EventArgs args)
  373. {
  374. OnDataSourceViewChanged (EventArgs.Empty);
  375. }
  376. ParameterCollection GetParameterCollection (ref ParameterCollection output)
  377. {
  378. if (output != null)
  379. return output;
  380. output = new ParameterCollection ();
  381. output.ParametersChanged += new EventHandler (ParametersChanged);
  382. if (IsTrackingViewState)
  383. ((IStateManager) output).TrackViewState ();
  384. return output;
  385. }
  386. protected virtual string ParameterPrefix {
  387. get { return "@"; }
  388. }
  389. StateBag viewState;
  390. private StateBag ViewState {
  391. get {
  392. if (viewState != null)
  393. return viewState;
  394. viewState = new StateBag ();
  395. if (IsTrackingViewState)
  396. viewState.TrackViewState ();
  397. return viewState;
  398. }
  399. }
  400. ParameterCollection deleteParameters;
  401. ParameterCollection filterParameters;
  402. ParameterCollection insertParameters;
  403. ParameterCollection selectParameters;
  404. ParameterCollection updateParameters;
  405. bool tracking;
  406. string name;
  407. SqlDataSource owner;
  408. #region OnDelete
  409. static readonly object EventDeleted = new object ();
  410. protected virtual void OnDeleted (SqlDataSourceStatusEventArgs e)
  411. {
  412. if (!HasEvents ()) return;
  413. SqlDataSourceStatusEventHandler h = Events [EventDeleted] as SqlDataSourceStatusEventHandler;
  414. if (h != null)
  415. h (this, e);
  416. }
  417. public event SqlDataSourceStatusEventHandler Deleted {
  418. add { Events.AddHandler (EventDeleted, value); }
  419. remove { Events.RemoveHandler (EventDeleted, value); }
  420. }
  421. static readonly object EventDeleting = new object ();
  422. protected virtual void OnDeleting (SqlDataSourceCommandEventArgs e)
  423. {
  424. if (!HasEvents ()) return;
  425. SqlDataSourceCommandEventHandler h = Events [EventDeleting] as SqlDataSourceCommandEventHandler;
  426. if (h != null)
  427. h (this, e);
  428. }
  429. public event SqlDataSourceCommandEventHandler Deleting {
  430. add { Events.AddHandler (EventDeleting, value); }
  431. remove { Events.RemoveHandler (EventDeleting, value); }
  432. }
  433. #endregion
  434. #region OnFiltering
  435. static readonly object EventFiltering = new object ();
  436. protected virtual void OnFiltering (SqlDataSourceFilteringEventArgs e)
  437. {
  438. if (!HasEvents ()) return;
  439. SqlDataSourceFilteringEventHandler h = Events [EventFiltering] as SqlDataSourceFilteringEventHandler;
  440. if (h != null)
  441. h (this, e);
  442. }
  443. public event SqlDataSourceFilteringEventHandler Filtering {
  444. add { Events.AddHandler (EventFiltering, value); }
  445. remove { Events.RemoveHandler (EventFiltering, value); }
  446. }
  447. #endregion
  448. #region OnInsert
  449. static readonly object EventInserted = new object ();
  450. protected virtual void OnInserted (SqlDataSourceStatusEventArgs e)
  451. {
  452. if (!HasEvents ()) return;
  453. SqlDataSourceStatusEventHandler h = Events [EventInserted] as SqlDataSourceStatusEventHandler;
  454. if (h != null)
  455. h (this, e);
  456. }
  457. public event SqlDataSourceStatusEventHandler Inserted {
  458. add { Events.AddHandler (EventInserted, value); }
  459. remove { Events.RemoveHandler (EventInserted, value); }
  460. }
  461. static readonly object EventInserting = new object ();
  462. protected virtual void OnInserting (SqlDataSourceCommandEventArgs e)
  463. {
  464. if (!HasEvents ()) return;
  465. SqlDataSourceCommandEventHandler h = Events [EventInserting] as SqlDataSourceCommandEventHandler;
  466. if (h != null)
  467. h (this, e);
  468. }
  469. public event SqlDataSourceCommandEventHandler Inserting {
  470. add { Events.AddHandler (EventInserting, value); }
  471. remove { Events.RemoveHandler (EventInserting, value); }
  472. }
  473. #endregion
  474. #region OnSelect
  475. static readonly object EventSelected = new object ();
  476. protected virtual void OnSelected (SqlDataSourceStatusEventArgs e)
  477. {
  478. if (!HasEvents ()) return;
  479. SqlDataSourceStatusEventHandler h = Events [EventSelected] as SqlDataSourceStatusEventHandler;
  480. if (h != null)
  481. h (this, e);
  482. }
  483. public event SqlDataSourceStatusEventHandler Selected {
  484. add { Events.AddHandler (EventSelected, value); }
  485. remove { Events.RemoveHandler (EventSelected, value); }
  486. }
  487. static readonly object EventSelecting = new object ();
  488. protected virtual void OnSelecting (SqlDataSourceSelectingEventArgs e)
  489. {
  490. if (!HasEvents ()) return;
  491. SqlDataSourceSelectingEventHandler h = Events [EventSelecting] as SqlDataSourceSelectingEventHandler;
  492. if (h != null)
  493. h (this, e);
  494. }
  495. public event SqlDataSourceSelectingEventHandler Selecting {
  496. add { Events.AddHandler (EventSelecting, value); }
  497. remove { Events.RemoveHandler (EventSelecting, value); }
  498. }
  499. #endregion
  500. #region OnUpdate
  501. static readonly object EventUpdated = new object ();
  502. protected virtual void OnUpdated (SqlDataSourceStatusEventArgs e)
  503. {
  504. if (!HasEvents ()) return;
  505. SqlDataSourceStatusEventHandler h = Events [EventUpdated] as SqlDataSourceStatusEventHandler;
  506. if (h != null)
  507. h (this, e);
  508. }
  509. public event SqlDataSourceStatusEventHandler Updated {
  510. add { Events.AddHandler (EventUpdated, value); }
  511. remove { Events.RemoveHandler (EventUpdated, value); }
  512. }
  513. static readonly object EventUpdating = new object ();
  514. protected virtual void OnUpdating (SqlDataSourceCommandEventArgs e)
  515. {
  516. if (!HasEvents ()) return;
  517. SqlDataSourceCommandEventHandler h = Events [EventUpdating] as SqlDataSourceCommandEventHandler;
  518. if (h != null)
  519. h (this, e);
  520. }
  521. public event SqlDataSourceCommandEventHandler Updating {
  522. add { Events.AddHandler (EventUpdating, value); }
  523. remove { Events.RemoveHandler (EventUpdating, value); }
  524. }
  525. #endregion
  526. }
  527. }
  528. #endif