专注

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

测试环境: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. 重新编译项目

 

image

posted on 2012-04-24 16:36  中金黄金  阅读(606)  评论(0编辑  收藏  举报