Solved

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb.net 2 37
Help with solving error related to resources file 4 36
Help with AsEnumerable(), LINQ 4 22
C#.NET and microsoft certification. 3 32
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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 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

22 Experts available now in Live!

Get 1:1 Help Now