Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Barcode Descriptions
111 - Redbull
112 - Vodka
112 - Vodka

How can I don't let two barcodes 112 and 112 in column 1 without primary key because I have done relationship with access.

What I have tried:

I tried to search in internet and not found, tried this code but not working for me.
Posted
Updated 25-Jul-16 1:46am
v9
Comments
[no name] 15-Jul-16 4:36am    
How is about a unique index?

For your case, you can see if there is a record with 112 as a value before adding 112 as column value in a new record.
SELECT Barcode WHERE Barcode = 112

This would do the trick. You can pass the 112 as a parameter (but that is a different story). Otherwise, in my own recommendation it is better to use a primary key and set that column to identity so that the database engine itself ensures that a duplicate data is not entered, and if that happens, an error is raised.
 
Share this answer
 
Comments
ionMEMBER 13-Jul-16 3:54am    
Thanks for answere but I need a code for more barcodes and not one (112).
This code does not work for me.
You have any ideas?
Richard MacCutchan 13-Jul-16 4:49am    
Do not use the hardcoded value, but the value entered by the user or device etc.
Afzaal Ahmad Zeeshan 13-Jul-16 6:27am    
Do as Richard has said, I was just trying to avoid making this answer a very complex one. Otherwise, I could has shown you how to pass parameters. Parameters will have the values that would be used to check against the value. Have a look here on MSDN.
SELECT barcode
FROM TABLE1
GROUP BY barcode
HAVING barcode = Entered_Barcode
 
Share this answer
 
Comments
ionMEMBER 19-Jul-16 15:47pm    
Thanks.. :)
But where should I put this code?
In button1? because If I put this code in button1, I show more error:
-Statements and labels are not valid between 'Select Case' and first 'Case'.
-'Select Case' must end with a matching 'End Select'.
ETC.
ionMEMBER 21-Jul-16 19:21pm    
Can you help me?
Look at the usage of DISTINCT in SQL.
SQL SELECT DISTINCT Statement[^]
 
Share this answer
 
Comments
ionMEMBER 13-Jul-16 16:10pm    
Thanks but not with SQL. ACCESS ?
Patrice T 13-Jul-16 16:23pm    
What is the problem with ACCESS ?
Use Improve question to update your question.
ionMEMBER 14-Jul-16 15:55pm    
Its not problem. I make realationship with 4 tables on access and I do not want to do primary key for this table because my program not functioned with primary key. If there is any way to make the primary key without access? THANKS .

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