Solved

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

Posted on 2008-06-13
5
1,241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
API v SOA 8 61
Telerik RadEditor Control Save 8 36
How we can add Dten600.dll in GAC in c#. 18 50
ASP.NET Load html part first, then start function 2 35
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

734 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