Hi,
My access db has 70 table and i want to list all table's name in a dropdown control. How can i do that?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kirtan PatelPosted Oct 22, 2009, 11:56 AM
Here I coded How to List Tables
please check "Do you like this answer" if it helps you :)
using System.Data.Common;
using System.Data.OleDb;
private void button1_Click(object sender, EventArgs e)
{
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\school.mdb;Persist Security Info=True");
DataTable dt = new DataTable();
//Get Only User Created Tables Not System Tables
string[] Restrictions = new string[4];
Restrictions[3] = "Table";
con.Open();
dt = con.GetSchema("Tables", Restrictions);
int i = 0;
comboBox1.Items.Clear();
foreach (DataRow r in dt.Rows)
{
comboBox1.Items.Add(r[2].ToString());
}
}
Master BillaPosted Oct 22, 2009, 9:51 PM
You use this code
private void LoadAllTables()
{
theLizardPosted Oct 22, 2009, 5:48 PM
"SELECT MSysObjects.Name FROM MsysObjects WHERE (Left$([Name],1)<>'~') AND (Left$([Name],4) <> 'Msys') AND (MSysObjects.Type)=1 ORDER BY MSysObjects.Name;";