|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DataAdapter Update gives "INSERT" errorDA_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 Run SQL Profiler to see the actual SQL that is being sent to SQL Server.
Very handy tool Jeff Show quote "Paul" <P***@discussions.microsoft.com> wrote in message news:13864F83-BEA0-4DEB-80AA-335670BFCBE0@microsoft.com... > 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 Thanks, Jeff - I'll try it.
Show quote "Jeff Dillon" wrote: > Run SQL Profiler to see the actual SQL that is being sent to SQL Server. > Very handy tool > > Jeff > > "Paul" <P***@discussions.microsoft.com> wrote in message > news:13864F83-BEA0-4DEB-80AA-335670BFCBE0@microsoft.com... > > 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 > > > 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'' Show quote "Jeff Dillon" wrote: > Run SQL Profiler to see the actual SQL that is being sent to SQL Server. > Very handy tool > > Jeff > > "Paul" <P***@discussions.microsoft.com> wrote in message > news:13864F83-BEA0-4DEB-80AA-335670BFCBE0@microsoft.com... > > 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 > > > |
|||||||||||||||||||||||