Solved

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

Posted on 2008-06-13
5
1,222 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now