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:<ol><li><strong>devices</strong> - brand, model, color, price, stock,min_stock</li> <li><strong>parts</strong> - brand, model, description,stock,min_stock</li> </ol>
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:<ul><li>Each time new brands and models appear so i need an option to add a new model/brand to the database and then update the drop down list to have them automatically </li> <li>The drop lists needs to be connected so if I choose brand A only brands A models will appear in the model drop list</li> </ul>Answer1:
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
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 <strong>relation</strong> 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".
<strong>EDIT</strong><br /> 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.