C#打开mdb文件,获取文件下的所有表格,以及获取表格下的所有字段

 1 String connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|aspxWeb2.mdb;";
 2 OleDbConnection conn = new OleDbConnection(connectionString);
 3 conn.Open();
 4 DataTable schemaTable;
 5 DataTable dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
 6 for (int i = 0; i < dt.Rows.Count; i++)
 7 {
 8   String tableName = dt.Rows[i]["TABLE_NAME"].ToString();
 9   Response.Write("<h1>" + tableName + "</h1>");
10   schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, new Object[] { null, null, tableName, null });
11   for (int j = 0; j < schemaTable.Rows.Count; j++)
12   {
13     Response.Write("<li>字段名称:" + schemaTable.Rows[j]["COLUMN_NAME"].ToString() + " 类型:" + (OleDbType)schemaTable.Rows[j]["DATA_TYPE"] + "</li>");
14   }
15 }
16 conn.Close();

http://www.2cto.com/kf/201203/125618.html

posted @ 2015-03-09 10:46  寻梦放歌  阅读(3549)  评论(0编辑  收藏  举报