Isolating and Reintegrating Changes

Questions That Should Be Asked More Frequently

  1. Q. How do the Data Adapter Configuration Wizard and CommandBuilder objects handle a scenario in which I want to refresh the contents of my row after submitting an update? Some things seem to work automatically, but others don't.

  2. A. The wizard will include queries to refresh your data immediately after you submit a new row or modify an existing row if your database supports such features. You will get these queries if you're using SQL Server or MSDE, but not if you're using databases such as Oracle or Access that don't support batched queries that return rows. If you do not want the Data Adapter Configuration Wizard to generate these refresh queries, click the Advanced Options button in the wizard and turn this feature off.

    The CommandBuilder object does not generate refresh queries no matter what back end you're using.

  3. Q. I have cascading referential integrity constraints in my database. If I delete an existing customer, the database automatically deletes the remaining orders for that customer. If I have deleted customers and orders in my DataSet, I get errors when I try to submit those changes, even though it looks like all the changes succeeded when I look at the contents of my database. What's going on?

  4. A. If you have a DataRelation defined between orders and details DataTable objects in your DataSet and you delete an order, ADO.NET will automatically mark the related child rows as deleted. Some databases allow you to define cascading referential integrity constraints in a similar fashion. So, when you submit the pending delete on the order, the database will delete the order and the related child rows from your database.

    However, ADO.NET will not know that the database has cascaded the change. The child rows will still be marked as pending deletions in the ADO.NET DataSet. If you submit the pending changes stored in the child DataTable to your database, the DataAdapter will attempt to delete the rows you've already deleted because of the database's cascading rules.

    The simplest solution is to use the techniques for submitting pending changes from a hierarchical DataSet that I described earlier in the chapter. Use the Select method of the DataTable to submit new rows, starting at the top level of the hierarchy and working your way down. Submit pending deletions starting at the bottom level or levels of the hierarchy, working your way up to the top.

  5. Q. The ADO Recordset object has a Resync method that you can use to fetch information on rows that did not update successfully. What is the equivalent method in the ADO.NET object model?

  6. A. The ADO.NET object model has no direct equivalent of this feature. However, you can achieve similar functionality by filling a new DataSet and merging the contents into your existing DataSet using the Merge method, as described earlier in the chapter.



Microsoft ADO. NET Core Reference
Microsoft ADO.NET (Core Reference) (PRO-Developer)
ISBN: 0735614237
EAN: 2147483647
Year: 2002
Pages: 104
Authors: David Sceppa

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net