473,387 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problem with saving changes of DataSet to database with relations

5
Database: 2 parent tables + 1 child table (child of both parent tables), enforcing foreign key constraints

App: winformsapp, stuff (dataset, datatables, tableadatpers) generated by designer

Thanks constraints (server's database) I must save changes in this order:
1. If I'm adding rows:
a) add parents rows
b) then add child rows
2. If I'm removing rows:
a) add child rows
b) then add parent rows
3. If I'm changing/updating --> doesn't matter

So I cannot use tableadapter's Update method, because I need to isolate updating of added rows (DataRowState.Added) and removed rows (DataRowState.Deleted).

My datatables use datacolumns with Expression property which uses Parent/Child relationship. So datable's GetChanges throws an exception (getchanges method creates a clone with no parents/children).

DataSet's GetChanges doesn't work with added rows, because during update operation is primary key updated from database (you know, something like: insert into .... ; select ... from ... where primarykey = SCOPE_IDENTITY()) and after merging I have 2 copies of each of added row.

I'm tired. I was googling for long time (and also studing help, trying own solutions) but I really didn't find answer anywhere.


Any HELP GREATLY APPRECIATED.


NOTE: please don't tell me anything like this:
don't use FK constraints in database, don't use datacolumn's expressions, have you defined keys on your tables?, etc.

I would be also happy to use deigner's generated code because datatables are quiet complex.



Technical details:
MS SQL Server Express Edition
.NET Framework 2.0
Windows Application
.Net SqlClient Data Provider
Microsoft Visual Studio 2005 Express Edition
Oct 19 '07 #1
6 2832
Shashi Sadasivan
1,435 Expert 1GB
1. If I'm adding rows:
a) add parents rows
b) then add child rows
2. If I'm removing rows:
a) add child rows
b) then add parent rows
3. If I'm changing/updating --> doesn't matter
Please chage that to
1. If I'm adding rows:
a) add parents rows
b) then add child rows
2. If I'm removing rows:
a) remove child rows
b) then remove parent rows
3. If I'm editing --> doesn't matter

I understand that it was a typo, but should work.
Oct 19 '07 #2
x5Rb
5
Thanks, you're right, but I can't edit it.

BTW: if you have any suggestions, post it, please.
Oct 19 '07 #3
Shashi Sadasivan
1,435 Expert 1GB
Thanks, you're right, but I can't edit it.

BTW: if you have any suggestions, post it, please.
Does it throw any sort of error/exception or it just plainly cpmpletes the operation, but does no change to the DB?
Oct 19 '07 #4
x5Rb
5
Does it throw any sort of error/exception or it just plainly cpmpletes the operation, but does no change to the DB?
DB (on the server) is correctly updated.

Maybe I didn't write it clearly, but:
1. I can't simply use dataadapter method to not violate (server-side) FK constraint.
2. If I use dataset's getchanges+dataadpater's update+dataset's merge it doesn't merge added rows correctly (client-side has 2 copies of the same row with different primary key values).

I could simply reload all data after update but that's what I don't want to do.
Oct 19 '07 #5
x5Rb
5
OK, let it be, I solved it QAD (quick and dirty):

1. PKs of all tables in client-side: autoincrement step=-1, autoincrement seed=-1
2. PKs of all tables in DB: autoincrement step=1, autoincrement seed=1
3. after dataset's Merge I look up and delete all rows with negative primary keys
Oct 19 '07 #6
x5Rb
5
I am here again, my QAD doesn't work. ADO.NET is crap.

For my example:

Expand|Select|Wrap|Line Numbers
  1. mydataset.GetChanges(); //returns also rows with DataRowState.Unchanged
  2.  
  3. mytable1TableAdapter.Update(mydataset.mytable1); //also child's rows are modified to DataRowState.Unchanged, so they will not be updated!!!
Oct 20 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Frosty | last post by:
Hi I am using the VS xsd designer to create a strongly typed dataset. The dataset is apparently successfully created, with no warnings or errors given. Is it not then to be expected that this...
1
by: Horatiu Ripa | last post by:
Once defined in SQL a database, with keys, indexes and relations between tables is it possible to create a DataSet to reflect all that? Basically I don't want to reestablish the relations, to set...
5
by: Jeff | last post by:
IDE: VS 2003 :NET OS: XP Pro My app have a form with a tab-control on it. The tab-control have 2 tabpages. One of the tabpages displays a datagrid, and the other tabpage displays details (order...
1
by: WhiskyRomeo | last post by:
Since I can't get answer from the author, can someone address this? In this article . . . http://msdn.microsoft.com/msdnmag/issues/04/05/DataPoints/default.aspx In the "The Transaction and...
5
by: Mika M | last post by:
Hello! I have Windows Forms application form containing TextBoxes, six ComboBoxes, and DataGrid for details. I have created DataSet with needed tables, and created relations between tables, and...
6
by: Brian Henry | last post by:
Here's an example of the code.. I have two combo boxes on screen that when one's selection is change the other's items will be updated to reflect the change (based on a relation) Private...
14
by: Lars Netzel | last post by:
A little background: I use three Datagrids that are in a child parent relation. I Use Negative Autoincrement on the the DataTables and that's workning nice. My problem is when I Update these...
6
by: BobLewiston | last post by:
When I try to save a new (inserted) record in an SQL database, I get the following System.Runtime.InteropServices.ExternalException message: I have to either find out how to insert an...
2
by: BobLewiston | last post by:
Some of you may have seen my earlier thread “PasswordHash NULL problem”. I’ve started a new thread because investigation has shown that the problem is actually quite different than I previously...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.