How to load all tables from access database into a combobox

Viewed 214

I'm new to programming and have been looking for quite a while on the internet on how to resolve my issue but sadly with no success. Can some of you please help me out?

So I have an access database with different tables and I want all tables to appear in a combobox for example: tblFood, tblCars, tblAnimals...

OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\School\Stage\Program testen\Program\bin\Debug\InventoryDB.accdb");

private void Form1_Load(object sender, EventArgs e)
{
    con.Open();
    OleDbCommand command = new OleDbCommand();
    command.Connection = con;
    string query = "Select * from ALL THE TABELS IN ACCESS";
    command.CommandText = query;

    OleDbDataReader reader = command.ExecuteReader();
    while (reader.Read())
    {
        comboBoxTabel.Items.Add(reader["ADD THE TABLES TO COMBOBOX"].ToString());
    }
    con.Close();
}
1 Answers
Related