Hi Hardin,
A dataset will cascade the AcceptChanges() and RejectChanges() through
DataRelations by default. However, you can change this behavior by set the
Accept/ Reject Rule to None when designing the DataRelation in the Edit
Relation dialog box. You can also change it in code. I've written a code
snippet to achieve this: (Since casting Constraints to ForiegnKeyConstraint
is not safe, we have to check it first.)
if(this.dataset11.Orders.Constraints["CustomersOrders"] is
ForeignKeyConstraint)
{
fkc =
(ForeignKeyConstraint)this.dataset11.Orders.Constraints["CustomersOrders"];
fkc.AcceptRejectRule = AcceptRejectRule.None;
}
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
--------------------
| Reply-To: "Hardin" <(E-Mail Removed)>
| From: "Hardin" <(E-Mail Removed)>
| Subject: Please help me understand
| Date: Mon, 3 Nov 2003 15:12:43 -0700
| Lines: 60
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <(E-Mail Removed)>
| Newsgroups: microsoft.public.dotnet.framework.adonet
| NNTP-Posting-Host: sdn-ap-031caburbp0431.dialsprint.net 65.179.129.177
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:65280
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| I have a typed dataset with 3 datatables from Northwind: Customers,
Orders,
| and Order Details with the appropriate relations and cascade updates and
| deletes set in the dataset.
|
| I have a SQLDataAdapter for each table, with Wizard-generated stored
| procedures used for Select, Update, Insert, and Delete.
|
| At update time, I use GetChanges to get a new dataset, return that dataset
| to a middle-layer, and run the following code (the dataset of just changed
| data is called "ds"

based on code in David Sceppa's book:
|
|
| //Update order: Deletes, Updates, Inserts
| try
| {
| // Deletes go from bottom up
| daDetails.Update(ds.Tables["Order Details"].Select("", "",
| DataViewRowState.Deleted));
| daOrders.Update(ds.Tables["Orders"].Select("", "",
| DataViewRowState.Deleted));
| daCust.Update(ds.Tables["Customers"].Select("", "",
| DataViewRowState.Deleted));
|
| // Updates go from top down
| daCust.Update(ds.Tables["Customers"].Select("", "",
| DataViewRowState.ModifiedCurrent));
| daOrders.Update(ds.Tables["Orders"].Select("", "",
| DataViewRowState.ModifiedCurrent));
| daDetails.Update(ds.Tables["Order Details"].Select("", "",
| DataViewRowState.ModifiedCurrent));
|
| //Inserts go from top down
| daCust.Update(ds.Tables["Customers"].Select("", "",
| DataViewRowState.Added));
| daOrders.Update(ds.Tables["Orders"].Select("", "",
| DataViewRowState.Added));
| daDetails.Update(ds.Tables["Order Details"].Select("", "",
| DataViewRowState.Added));
| }
| ....
|
| First, there are no exceptions thrown during this process.
|
| However, the update process appears to be incomplete, and it seems to be
| caused by a problem with the DataAdapter.Update method. After one of the
| statements above executes, the dataAdapter (according to MS's
documentation)
| calls AcceptChanges. If it called AcceptChanges just on each row as it
was
| sent to the SQL StoredProcedure, that would be fine. But instead, it
seems
| to either be calling it on the entire dataset or else AcceptChanges is
| bubbling down the relations change in the dataset. In any case, if there
| are changes or updates to more than one table, this routine only updates
one
| but marks all pending changes as unchanged.
|
| Any suggestions, code samples, property settings, etc., that anyone can
| suggest to make this work?
|
| Thanks a lot,
| -- Hardin
|
|
|