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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 22, 2009, 7:56 AM EDT
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());
}
}
theLizardRank #1,079 · 1.8K reputationPosted Oct 22, 2009, 1:48 PM EDT
"SELECT MSysObjects.Name FROM MsysObjects WHERE (Left$([Name],1)<>'~') AND (Left$([Name],4) <> 'Msys') AND (MSysObjects.Type)=1 ORDER BY MSysObjects.Name;";
Master BillaRank #2,229 · 630 reputationPosted Oct 22, 2009, 5:51 PM EDT
You use this code
private void LoadAllTables()
{
// Microsoft Access provider factory DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb"); DataTable userTables = null; using (DbConnection connection = factory.CreateConnection()) { // c:\test\test.mdb connection.ConnectionString = "Provider=Microsoft .Jet.OLEDB.4.0;Data Source=c:\\test\\test.mdb"; // We only want user tables, not system tables string[] restrictions = new string[4]; restrictions[3] = "Table"; connection.Open(); // Get list of user tables userTables = connection.GetSchema("Tables", restrictions); } // Add list of table names to listBox for (int i=0; i userTables.Rows.Count; i++) listBox1.Items.Add(userTables.Rows[i][2].ToString()); } thank you