Peter Hall
Peter Hall

Reputation: 11

SQL and C# - Tabs from SQL database

Hi in try to make tabs for every type of product in a database

My database looks like this:

Id     Product 
1      Bananas   
2      Bananas   
3      Grapes   
4      Strawberrys   
5      Strawberrys   
6      Oranges  

i've made the connection between a form in c# and the database and able to do simple queries.

i've got a TabControl, called Tabcontrol1, i was wondering how i would query the database and output the products into a tabcontrol but like in the example the banana's are there multiple times, but i dont need the duplicate, so to skip the other one, theres going to be about 20 products altogether.

So my tab control would look like this:

____________________________________________
| Bananas | Grapes | Strawberrys | Oranges |___________________

Any experts able to help?

Thanks

Upvotes: 1

Views: 1038

Answers (3)

user1841665
user1841665

Reputation:

Get the product names from the db and then create foreach() loop to assign return values to the tab control to create a specific tab for each product name

Upvotes: 0

Gustav Klimt
Gustav Klimt

Reputation: 440

Make a query that will only show unique entrys: Select distinct product FROM table.

Save those rows to array/datatable/whatever.

Cruise trough collection with foreach (or whatever makes u tick) and for each row/item:

tabcontrol1.TabPages.Add(stringName);

hope it help.

Upvotes: 0

Yatrix
Yatrix

Reputation: 13785

Use SELECT DISTINCT Product FROM YourTable to get back no duplicates from the database.

Then, just loop through the returned dataset and create tabs for each result.

http://msdn.microsoft.com/en-us/library/zb7xae05.aspx

I didn't write all of the code out as this site operates under the assumption you know how to program. You'll need to call a stored procedure from your .NET code or pass in the sql command I gave you above and that should get you on your way.

Upvotes: 1

Related Questions