DataAdapter Update gives "INSERT" error

G

Guest

When I try to update my data source using
DA_InstalledItems.Update(DS_InstalledItems)
I get this error:
Violation of PRIMARY KEY constraint 'PK_VehicleItems'. Cannot insert
duplicate key in object 'dbo.VehicleItems'. The statement has been
terminated."

DA_InstalledItems.UpdateCommand.CommandText is:
"UPDATE VehicleItems SET ItemID=@ItemID,
ItemSerialNumber=@ItemSerialNumber, PartNumber=@PartNumber,
Description=@Description, Level=@Level, LevelSortOrder=@LevelSortOrder,
ItemSequence=@ItemSequence, Who=@Who, WhenChanged=@WhenChanged WHERE
VehicleId =802"

Any ideas what's happening?

TIA,

Paul
 
J

Jeff Dillon

Run SQL Profiler to see the actual SQL that is being sent to SQL Server.
Very handy tool

Jeff
 
G

Guest

Jeff-

I'm pasting the Profiler output below. The DataAdapter's table has 12 rows.
Its RowUpdating event fires twice. After the second RowUpdating event the
error occurs, with the "Primary Key" error noted earlier. (The table's
primary key is composed of 3 columns, none of which are being updated. Only
one other column is being updated.)

Only one Update command shows up in the Profiler, corresponding to the first
row of the DataAdapter's table to be updated. The Profiler shows no evidence
of being sent a second row:
-----------------------------------------------------------------------------------

exec sp_executesql N'UPDATE VehicleItems SET ItemID=@ItemID,
ItemSerialNumber=@ItemSerialNumber, PartNumber=@PartNumber,
Description=@Description, Level=@Level,
LevelSortOrder=@LevelSortOrder, ItemSequence=@ItemSequence, Who=@Who,
WhenChanged=@WhenChanged WHERE VehicleId =809',N'@ItemID
int,@ItemSerialNumber nvarchar(20),@PartNumber
nvarchar(50),@Description nvarchar(150),@Level nvarchar(50),@LevelSortOrder
int,@ItemSequence int,@Who nvarchar(50),@WhenChanged
datetime',@ItemID=76,@ItemSerialNumber=N'8084-23',@PartNumber=N'MANUAL',@Description=N'Owner''s
Manual',@Level=N'Robot',@LevelSortOrder=1,@ItemSequence=1,@Who=N'JDB',@WhenChanged=''2006-02-23 11:55:35:000''
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top