Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Need Help.

I have created a Windows application in VB.NET which collects user inputs and stores them in MS Access 2003 database.

However I have been searching for VB.NET code that I can use to validate information entered through the VB.NET interface, most importantly I want code that would validate data entered from being duplicated in the database.

Specifically, I want code that would validate the primary key from being entered which would produce a duplicated record.

Thanks.
Posted
Updated 23-Nov-10 23:49pm
v2
Comments
Maciej Los 23-Nov-10 16:29pm    
So, you should ask your database...
Need more information about your database, a specialy about primary key, relations...

In MS Access if you set your key to be Primary and it is unique then it would be impossible for you to enter a duplicate value. The database won't let you perform a duplicate action on a key that already exists.

If you are doing this through code then you would want to perform a SQL statement against the database looking up the key value. If no records are returned then you know that your key value is unique.

Please note, that if you are going up against a large table in your database, and since it is Access, you are going to most likely have problems with performance.

I would recommend that you use SQL Server Express 2005/2008, it is lightweight and powerful and is better in performance than MS Access. It will also allow you to use Stored Procedures and Triggers among other things as well. Good luck!

HTH
 
Share this answer
 
Further to Slacker007's answer

If you enter duplicate values in a Primary Key column it will through an error in your code.

But if I remember rightly in Access you can use a autonumber column.
 
Share this answer
 
Comments
Slacker007 24-Nov-10 10:11am    
That is correct Simon. There is a Autonumber property for the column if it is going to be used as a primary key.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900