PC Review


Reply
Thread Tools Rate Thread

Please help me understand

 
 
Hardin
Guest
Posts: n/a
 
      3rd Nov 2003
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


 
Reply With Quote
 
 
 
 
Cor
Guest
Posts: n/a
 
      4th Nov 2003
Hi Hardin,

If it is for learning I don't have an answer, if it is for using, take a
look for SQLcommandbuilder or Oledbcommandbuilder.

Saves you a lot of work.

Cor


 
Reply With Quote
 
 
 
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      4th Nov 2003
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
|
|
|

 
Reply With Quote
 
David Sceppa
Guest
Posts: n/a
 
      4th Nov 2003

Actually, there's an error in the documentation regarding
that behavior.

When you submit the pending change in a DataRow by calling
DataAdapter.Update, the DataAdapter will implicitly call the
DataRow's AcceptChanges method if it successfully submitted the
pending change stored in the row.

If you have a DataRelation that points to child rows, this
implicit call to AcceptChanges will cascade down to the related
child rows if the DataRelation's ForeignKeyConstraint's
AcceptRejectRule property is set to Cascade. There's an error in
the documentation that states that this property is set to
Cascade by default. The actual default is None, which means that
the call should not cascade down to the related child rows. Some
developers have seen that error in the documentation and have set
the AcceptRejectRule property to Cascade.

Hardin, please check this property in your code. If it's
set to Cascade, set it to None instead. If this does not explain
the behavior and resolve your problem, please let us know.

I hope this information proves helpful.

David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2003 Microsoft Corporation. All rights reserved.

 
Reply With Quote
 
Hardin
Guest
Posts: n/a
 
      5th Nov 2003
Thank you, David.
That was indeed the problem -- the AcceptRejectRule was set to Cascade.
However, I'm pretty sure I didn't set it that way (I know I didn't set it
that way on purpose, in any case, but perhaps I fumbled with the XSD
relations designer/wizard).

Thank you for the reply.
-- Hardin

"David Sceppa" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> Actually, there's an error in the documentation regarding
> that behavior.
>
> When you submit the pending change in a DataRow by calling
> DataAdapter.Update, the DataAdapter will implicitly call the
> DataRow's AcceptChanges method if it successfully submitted the
> pending change stored in the row.
>
> If you have a DataRelation that points to child rows, this
> implicit call to AcceptChanges will cascade down to the related
> child rows if the DataRelation's ForeignKeyConstraint's
> AcceptRejectRule property is set to Cascade. There's an error in
> the documentation that states that this property is set to
> Cascade by default. The actual default is None, which means that
> the call should not cascade down to the related child rows. Some
> developers have seen that error in the documentation and have set
> the AcceptRejectRule property to Cascade.
>
> Hardin, please check this property in your code. If it's
> set to Cascade, set it to None instead. If this does not explain
> the behavior and resolve your problem, please let us know.
>
> I hope this information proves helpful.
>
> David Sceppa
> Microsoft
> This posting is provided "AS IS" with no warranties,
> and confers no rights. You assume all risk for your use.
> © 2003 Microsoft Corporation. All rights reserved.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PLEASE EXPLAIN IT TO ME LIKE A 3YR OLD KID WOULD UNDERSTAND PLEASE. Leegann Pomele Windows Vista Mail 2 24th Sep 2008 07:57 PM
Please help me understand driver installation process...! Jeff W Windows XP Drivers 12 28th Oct 2004 11:26 PM
Help! Anyone! Please Please Please Please Please Please =?Utf-8?B?UmFuZHk=?= Microsoft Access Macros 2 17th May 2004 07:16 PM
ACPI Problems (please HELP, Don't understand this part) olivan@doctor.com Windows XP Customization 1 10th Jan 2004 01:22 AM
Help! Help! Help! Help! Help! Help! Help! Help! Help! Help! Help! Help! Help! -$- Windows XP Internet Explorer 2 21st Dec 2003 11:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:10 PM.