Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 28th, 2006, 06:30 AM
Friend of Wrox
 
Join Date: Apr 2006
Location: , , .
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default can't update the primary key in a gridview

Hi,

I defined a gridview with an UpdateCommand.
When i click on 'update' i can update all fields excepted the primary key.
Is there any way to make it possible?
(I use Access and when runing a update-query in Access, i can also update
the primary key).

Thanks


 
Old May 28th, 2006, 03:42 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

T he point of a primary key is to be unique. If it is changed then the related tables will have orphan data. The grid view will now allow you to do that.

 
Old May 29th, 2006, 03:44 AM
Friend of Wrox
 
Join Date: Apr 2006
Location: , , .
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks again,

but it must be possible to change a primary key, e.g. in case it's not an auto-generated key and it has no relationship with other tables ...

 
Old May 29th, 2006, 10:31 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

You can allow the update of the PK by setting the ReadOnly property to FALSE. Then you will have to change the UPDATE comand in the datasource. However, I don't recommend this. There is NO reason for a user, or ANYONE to change a primary key, and that is why the gridview by default will not allow it, even if there is no related data or it is not an autogenerate column

 
Old May 30th, 2006, 04:04 AM
Friend of Wrox
 
Join Date: Apr 2006
Location: , , .
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, thanks for replying





Similar Threads
Thread Thread Starter Forum Replies Last Post
Update to add identity & primary key seananderson SQL Server 2005 2 July 18th, 2007 09:04 PM
Foreign key not updating with Primary key xavier1945 BOOK: Access 2003 VBA Programmer's Reference 2 July 4th, 2007 09:48 PM
Update Table with dataset without primary key ranakdinesh ASP.NET 2.0 Professional 1 September 28th, 2006 05:30 PM
FOREIGN KEY and PRIMARY KEY Constraints junemo Oracle 10 June 15th, 2004 01:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.