Master-Detail Updates in Transactions

G

Guest

I need to update, insert, delete rows from DataSet in transaction. (for each
master row and details rows in dataset i need to start new transaction)
If one row in detail table was modified, parent row exists in dataset which
returned by GetChanges method...this valid for updated and inserted records,
but if I remove some rows from Detail table parent row does not exists.

On web service which I use as Facade layer i use loop to get master and
detail rows and then execute update in transaction...but if dataset contains
"abandoned" rows they are can not be updated :(

Cound sombody explain me how implement master-detail update in
transaction...??
 
M

Miha Markic [MVP C#]

Hi,

First update New and Updated rows in this order:
master, detail
The update Deleted rows in reverse order:
detail, master.

You can get rows by executing Select method of DataTable, for example:
DataRow[] addedRows = table.Select(string.Empty, string.Empty,
DataViewRowState.Added);
....

Maybe it is easier to pack all updates into the same transaction, otherwise
Selects will be more complicated.
 
A

Alexandr

In my n-tier app all Updates, Inserts and Deletes are separated (I already
use GetChanges() with separate data row state... on client side and pass
changes to WebService). And I know how

My problem another. For example:

On client side i have deleted 2 rows in order details table, and one order
deleted full (with master and details rows).
After getting ahanges I have dataset wich contains deleted master and
deleted details for 1 order. and 2 details rows for another order.
I don't know how to implement correctry delete for this dataset, I want to
delete info for each order in separate transactions.


// for example
foreach(DataRow order in orderDeletedDataSet.Tables["orders"].Rows)
{
try
{
DataRow[] details = order.GetChildRows("FK");
BLLorders.Update(details);
BLLorders.Update(order);
ContextUtil.SetComplete();
}
catch
{
ContextUtil.SetAbort();
}
}


But i have "abandoned" rows in details table for 2-nd order and this rows
can not be deleted...How to implement trick for problem...
Is my algorithm bad? For updates and inserts this works tiptop...Could you
tell me solution?

Thanks in advance.


Miha Markic said:
Hi,

First update New and Updated rows in this order:
master, detail
The update Deleted rows in reverse order:
detail, master.

You can get rows by executing Select method of DataTable, for example:
DataRow[] addedRows = table.Select(string.Empty, string.Empty,
DataViewRowState.Added);
...

Maybe it is easier to pack all updates into the same transaction, otherwise
Selects will be more complicated.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

I need to update, insert, delete rows from DataSet in transaction. (for each
master row and details rows in dataset i need to start new transaction)
If one row in detail table was modified, parent row exists in dataset which
returned by GetChanges method...this valid for updated and inserted records,
but if I remove some rows from Detail table parent row does not exists.

On web service which I use as Facade layer i use loop to get master and
detail rows and then execute update in transaction...but if dataset contains
"abandoned" rows they are can not be updated :(

Cound sombody explain me how implement master-detail update in
transaction...??
 
A

Alexandr

No I don't wont to use this functionality...maybe you don't complete
understand my problem...please read my previous reply...i really need help

Miha Markic said:
Hi,

First update New and Updated rows in this order:
master, detail
The update Deleted rows in reverse order:
detail, master.

You can get rows by executing Select method of DataTable, for example:
DataRow[] addedRows = table.Select(string.Empty, string.Empty,
DataViewRowState.Added);
...

Maybe it is easier to pack all updates into the same transaction, otherwise
Selects will be more complicated.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

I need to update, insert, delete rows from DataSet in transaction. (for each
master row and details rows in dataset i need to start new transaction)
If one row in detail table was modified, parent row exists in dataset which
returned by GetChanges method...this valid for updated and inserted records,
but if I remove some rows from Detail table parent row does not exists.

On web service which I use as Facade layer i use loop to get master and
detail rows and then execute update in transaction...but if dataset contains
"abandoned" rows they are can not be updated :(

Cound sombody explain me how implement master-detail update in
transaction...??
 
M

Miha Markic [MVP C#]

Hi Alexandr,

Alexandr said:
No I don't wont to use this functionality

Since dataset is an unit, why don't you save it in one pass?
Otherwise, as I suggested, you'll have to implement some logic by yourself
(which record to delete, etc).

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

....maybe you don't complete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top