测试环境:WINDOWS 7 64位
IDE : VISUAL STUDIO 2008
源代码:
using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.OleDb;
namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=wojilu.mdb"; OleDbConnection conn = new OleDbConnection(ConnectionString); conn.Open();
DataTable schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" }); foreach (DataRow dr in schemaTable.Rows) { //表名 Console.WriteLine(dr["TABLE_NAME"]);
//字段名 DataTable columnTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, new object[] { null, null, dr["TABLE_NAME"].ToString(), null });
foreach (DataRow dr2 in columnTable.Rows) { Console.WriteLine(" {0} ", dr2["COLUMN_NAME"]); }
} conn.Close();
Console.Read(); } } }
|
如果你在运行过程中遇到以下问题:
The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine.
可以尝试以下步骤:
1. 右击解决你的解决方案,选择属性
2. 选择BUILD页
3. 将Platform target从 Any CPU 改为 x86
4. 重新编译项目