How to avoid duplicate ID When data entry ?

desmondtan

Active member
Joined
Dec 24, 2002
Messages
40
How to write the checking of databse to prevent the duplicate duplicate of certain ID ( such as Employee Number ) when user do the data entry in Windows form ?
 
If you have an option of disallowing duplicate table entries in your database then use that - what database are you using? You could then use Try, Catch to catch any exception that may be thrown if you try to entre a dup record.

If not you could use a SELECT sql command with a WHERE clause of the ID number you want to check for, if the sql select returns a record then the ID is already there if not then it is ok to insert data.

Stuart
 
It is better to use the datatype uniqueidentifier in SQL-Server.
with this as primary key you can guarantee that this is key only exists one in the world.
 
Can Weuse Try....catch...End try to catch the duplicate ID when updating ? What exception should use ?
 
ok suppose you dont want two ppl to have the same code name then what you can do is this

dim adr() as DataRow = Dataset.Tables("TableName").Select("EmpCode = " & CODE & "")
if adr.length = 0 Then
the code to allow him to enter the value in db
Else
sorry buddy value exists
End if
 
Back
Top