Reputation: 1083
I'm trying to build a simple inventory program for a friends cellphone store I want to use C# and access database to store the data
the DB will have 2 main lists:
the GUI will use several drop lists brand will give me : samsung, htc, ect'.... model will give me : I9000,i9100,ect...
the two main problems I have when I try to think how to make it are this:
Upvotes: 2
Views: 2496
Reputation: 56697
First of all: don't use Access, use SQL Server 2008 Express. But that's only personal taste.
What you need to do to achieve what you want: Create a typed dataset in Visual Studio that contains one table for brands and one for models. Associate the two tables using a relation on the brand
column.
Read both tables from the database - first the brands
table, then the models
table. Otherwise you'll get an error.
Create a master/detail binding for both lists. To do so, drop two BindingSource
instances to your form. Associate one of them to the "brands" list and one to the "devices" list. The datasource for the "brands" BindingSource
must be set to the brands
table in the dataset, the datasource for the other BindingSource
must be set to the relation between the two tables. All of this can be one in the designer.
If you have problems setting up the bindings, google for "C# master detail binding dataset".
EDIT
Another option - if the database connection is fast - would be to fill the list of brands from the database and whenever a brand is selected, clear and re-fill the list of models from the database on the fly using the selected brand name.
Upvotes: 3