desmondtan Posted February 28, 2003 Posted February 28, 2003 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 ? Quote
stustarz Posted February 28, 2003 Posted February 28, 2003 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 Quote Visit: VBSourceSeek - The VB.NET sourcecode library "A mere friend will agree with you, but a real friend will argue."
basesuck Posted March 3, 2003 Posted March 3, 2003 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. Quote
desmondtan Posted March 6, 2003 Author Posted March 6, 2003 Can Weuse Try....catch...End try to catch the duplicate ID when updating ? What exception should use ? Quote
a_jam_sandwich Posted March 6, 2003 Posted March 6, 2003 Send the error number to console and check there I think it is 5 though Andy Quote Code today gone tomorrow!
hemenkap Posted March 10, 2003 Posted March 10, 2003 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.