[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?
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
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
Re: Question About Primary key
techgnome : - thanks i see where i made my mistake now
cengineer : - also thanks for you input too
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