I’d previously asked a similar question, however it was slightly ambiguous and didn’t generate a viable answer. So i hope this question is fairly clear.
I have the following set up at a basic level, and Purely as an example.
SQL Database:
tableFood
foodType name ID
------- ---- --
fruit apple 1
veg' carrot 2
fruit pear 3
I have the following 3 forms in the application – which is linked using a MySQL source to the database.
Choice.VB :
Two buttons:
One says Fruit
One says Veg
Upon clicking either button the user is taken to a new form.
If they’ve clicked fruit they’re taken to
fruit.vb:
2 (dynamic) labels one containing the word apple, the other pear.
Seems simple enough, however behind the scenes when the user initially clicks fruit, the program should query the linked database/source (SQL based) for items where the name is fruit and then return these to the program which places the text value into the labels.
I’m completely stuck as to how to do this however.
Is it possible?
And if yes,
How?
This is very possible using ADO.NET. This link steps you through the entire process. However, nowadays I would suggest looking into LINQ or Entity Framework. Also, in the future, it is better to just update your original question (http://stackoverflow.com/questions/9538479/visual-studio-reference-specific-sql-database-item), than to create a new, duplicated one with better details.
Here is a sample using ADO:
Alternately, you could (and should in most cases) use commands for stored procedures (and gain protection against SQL injection)