views:

348

answers:

1

I have the next combobox:

this.comboBoxProd.Enabled = false;
this.comboBoxProd.FormattingEnabled = true;
this.comboBoxProd.Items.AddRange(new object[] {
            "Cameras",
            "------------",
            " Digital IXUS 850 IS ",
            " Digital IXUS 900 Ti ",
            " Digital IXUS 75 -NEW- ",
            " Digital IXUS 70 -NEW- ", etc.

I want to change it and take the values from a db. My database name is bd1.mdb and in the table Cameras it has the following fields: CamID, Cameras, Warranty, Year. I am only interested in the "Cameras" field. Thank you!

+2  A: 

You should take a closer look for ADO.NET operations with .mdb files here

First,prepare your connection string

string connString = "Microsoft.Jet.OLEDB.4.0;Data Source=C:\\bd1.mdb";

Next step is to prepare your query

string query = "SELECT Cameras FROM Cameras";

You will need an adapter to bind datasource,in your case it's OleDbDataAdapter

OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);

Now you can use a DataTable object to bind into combobox

DataTable source = new DataTable();

Fill data into your source

dAdapter.Fill(source);

Your source is full with Cameras,now you can refer to your combobox control

combobox.DataSource = source;

DO NOT FORGET THAT you should that which field will be displayed in Combobox items

combobox.DataTextField = "Cameras";//from query

Hope this helps
Myra

Myra
didn't helped me very much. i don't wont to modify the content of the database, i want to add content from it.
Bomboe Cristian
Sorry for inconvenience,Bomboe when I was writing the entire answer,I should have deleted rest of it.
Myra
ty, this really helped me!
Bomboe Cristian