Click here to Skip to main content
14,449,458 members
Rate this:
Please Sign up or sign in to vote.
See more:
I'm using vb 2005 with sql 2005

I've a table created in sql 2005 with a primary key. I'm imported the data in my dataset.

On my form I want VB to automatically prevent modification of the primary key field for an existing record.

how can this be done

thanks
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

Without knowing how you've displayed your data, it's hard to say. The easiest way though is to not show the primary key. I've rarely encountered a situation where the key provides any value for the user, so they should not care about it - which means they don't need to see it.
   
Comments
Marc A. Brown 12-May-11 11:37am
   
Good answer.
fez1 12-May-11 11:47am
   
let's say that the client code is the primary key and it is displayed on the screen. The user has the choice to query by the client code and the same screen is used for creating new clients and for viewing existing ones
Pete O'Hanlon 12-May-11 11:50am
   
You need to provide validation logic then and prevent the update based on this. If the primary key is already defined, then you should disable the entry field and only let it be enabled if there's no key already present. That's a simple boolean check.
Liju Sankar 13-May-11 2:00am
   
There are times where user has to see the primary keys, the better options is to disable the column for further editing
Pete O'Hanlon 13-May-11 2:10am
   
How many systems have you built where the key offers any real value to the user. When it's an identity value it has no real business value to the user so it should not be shown.
Rate this:
Please Sign up or sign in to vote.

Solution 2

Hi fez1,
It is totally depends on the way in which you retrieve the data, if you go with any of the 'typed data set' approaches like Object data source, it automatically mark primary key field are 'read only'
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100