|
-
Apr 15th, 2010, 09:33 AM
#1
Thread Starter
Lively Member
[RESOLVED] Question About Primary key
I have a database running on SQL server primary key is all set, my question is i dont want to allow duplicates in the primary key, i want everything to be uniqure. The database already has information in it, is there a away to set it so when i add a new row through the table adapter that it will recognise the last primary key value and increment it by +1?
-
Apr 15th, 2010, 09:38 AM
#2
Re: Question About Primary key
No... actually, you don't want the code setting the PKey. The way it should be working (at this this is how it works for us)... is that when you add a row, if the datatable knows it's a PKey (which it should if it's been setup right) the first add will get -1. The next -2, and so on. When the datatable is then .Updated with the database, the database generates the PKey (using what ever method is setup) and sends the PKey back to the datatable. the datatable will then have the correct PKey. The reason you don't want the datatable/code doing it is because if two people add a record.... and both get the same PKey.... you've got a problem.
-tg
-
Apr 15th, 2010, 09:39 AM
#3
Hyperactive Member
Re: Question About Primary key
cant you just set it to autoincrement in your sql server management studio(assume you are using this) and if it is a primary key, there should be unique.
Just a newbie view.
sorry...techgnome...ignore mine addntox
-- Please rate me if I am helpful --
-
Apr 15th, 2010, 09:44 AM
#4
Thread Starter
Lively Member
Re: Question About Primary key
techgnome : - thanks i see where i made my mistake now
cengineer : - also thanks for you input too
-
Apr 15th, 2010, 09:53 AM
#5
Re: [RESOLVED] Question About Primary key
cengineer - no, no, that's a valid point.... and one I glossed over. I assumed that the table in the database already had that autoincrement (Identity in SQL Server) already set. In fact, that's the only way it really does work.
-tg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|