Solved

SqlDataAdapter.Update Exception - how to get row/table of error

Posted on 2008-06-13
5
1,232 Views
Last Modified: 2010-08-05
I'm getting an exception on SqlDataAdapter.Update().  

The error message is "Table: eeeHomeOffice.dbo.SalePayments Exception: The record can't be added or changed. Referential integrity rules require a related record in table 'SaleHeader'.".
 
I dumped the DataSet to XML and can't see any relationship problems.

How do I tell what row and table is having the problem?

What order are the records written out?  The SaleHeader is the first table in the set and SalePayments is second.  Is it possible that it's trying to write SalePayments records first?

Some of the data sets are working fine, only a small percentage throw the exception.
0
Comment
Question by:GaryHoff
  • 2
  • 2
5 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 21785204
How are you working with the SqlDataAdapter?  Are you adding records to DataSet DataTables, and then calling the Update method?
0
 
LVL 1

Author Comment

by:GaryHoff
ID: 21786819
Dim dtSynchTable As DataTable
Dim adapter As New SqlDataAdapter("", conn)
.....
adapter.Update(dtSynchTable)

Mostly they are new records, but could be changed ones as well.
Mostly looking to determine which row had the exception.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 21786924
If you are adding rows to a single table at a time, then you need add them in the order of parent, and then child.
0
 
LVL 34

Accepted Solution

by:
Sancler earned 500 total points
ID: 21786950
>>
Mostly looking to determine which row had the exception.
<<

Unless you are using batch updates, you could AddHandler for the adapter's RowUpdated Event.  Have a look here

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.rowupdated(VS.80).aspx

and here

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlrowupdatedeventargs_members(VS.80).aspx

Roger
0
 
LVL 1

Author Comment

by:GaryHoff
ID: 21813001
that should do it.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question