Click here to Skip to main content
15,880,392 members
Articles / Database Development
Tip/Trick

List of Tables of Microsoft Access DataBase

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
17 Feb 2011CPOL 18.8K   5   1
While dealing with databases, sometimes there is a need to get a list of tables in the application
If you are making an application where you need to deal with a database, the following piece of code can help you in getting a list of available tables in the database.

void table()
        {
            string path = @"D:\....... your database file path";
            listBox1.Items.Clear();
            textBox1.Text = "";
            mycon = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Persist Security Info=True");
            mycon.Open();
            DataTable tables = mycon.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
            foreach (DataRow row in tables.Rows)
                listBox1.Items.Add(row[2]);
            mycon.Close();
            mycon.Dispose();
        }


Although there are many other methods, I have kept it simple for beginners.

Welcome to suggestions.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Pakistan Pakistan
I am a learner.

Comments and Discussions

 
QuestionViews Pin
evry1falls25-Apr-15 12:16
evry1falls25-Apr-15 12:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.