Solved

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

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

691 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