Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / April 2006

Tip: Looking for answers? Try searching our database.

DataAdapter Update gives "INSERT" error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paul - 21 Apr 2006 18:21 GMT
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 Dillon - 21 Apr 2006 19:59 GMT
Run SQL Profiler to see the actual SQL that is being sent to SQL Server.
Very handy tool

Jeff

> When I try to update my data source using
> DA_InstalledItems.Update(DS_InstalledItems)
[quoted text clipped - 15 lines]
>
> Paul
Paul - 21 Apr 2006 20:09 GMT
Thanks, Jeff - I'll try it.

> Run SQL Profiler to see the actual SQL that is being sent to SQL Server.
> Very handy tool
[quoted text clipped - 20 lines]
> >
> > Paul
Paul - 21 Apr 2006 20:57 GMT
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''

> Run SQL Profiler to see the actual SQL that is being sent to SQL Server.
> Very handy tool
[quoted text clipped - 20 lines]
> >
> > Paul

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.