2009-11-09 49 views
11

如果我可以在C#中打開與MS Access文件的連接,如何檢索Access數據庫中存在的不同表的列表(如果可能的話,還有任何元數據與表相關)?在MS Access文件中檢索表列表

+0

哪些元數據您需要了解有關以下解決方案? – 2009-11-09 21:08:27

+0

至少,該表的描述(如果保存的話) – 2009-11-10 04:25:05

+0

[我如何獲得Access(Jet)數據庫中的表的列表?](http://stackoverflow.com/questions/ 6152545/how-can-i-get-a-list-in-an-access-jet-database) – Fionnuala 2012-02-09 10:55:11

回答

25

我剛剛發現從David Hayden

// 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); 
} 

List<string> tableNames = new List<string>(); 
for (int i=0; i < userTables.Rows.Count; i++) 
    tableNames.Add(userTables.Rows[i][2].ToString()); 
+0

在特定列中查找最高數字的任何幫助?使用c# – gsvirdi 2011-07-16 05:00:46

1

下面的是一些鏈接:

這裏有一個VB.NET snipit得到一個訪問表的所有列,我知道這不是正是你」重新尋找,但列出所有表時,類似的原始蘋果:

Dim oleConn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & myDB & ";User Id=admin;Password=;") 

oleConn.Open() 
Dim schemaTable As DataTable 
Dim i As Integer 
schemaTable = oleConn.GetOleDbSchemaTable(OleDbSchemaGuid.Column s, _ 
New Object() {Nothing, Nothing, "tblTheTableToListColumns", Nothing}) 
For i = 0 To schemaTable.Columns.Count - 1 
Debug.Print(schemaTable.Rows(i)!COLUMN_NAME.ToStri ng) 
Next i 
oleConn.Close()