Windows 7 下打开Access数据库出错

来源:互联网 发布:编程单引号怎么打出来 编辑:程序博客网 时间:2024/06/10 18:59

如果你尝试在Windows7或其他64位操作系统下打开access 数据库,可能你会碰到如下的错误: System.InvalidOperationException: The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine.

为解决这个问题,你只需要打开Visual stadio, 进入菜单My Project -> compile -> advanced compiler options,设置一下 the target cpu to x86. 当然如果你用的是中文版,请选择相应菜单。由于当前没有64位的Jet.OLEDB.provider,所以这里只能通过设置CPU选项,强制 .NET framework使用32位的数据库引擎.     

 

数据库联接事例如下:

Dim ds As New DataSet

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim conn As OleDbConnection
        Dim strConn As String
        Dim da As OleDbDataAdapter

        strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"
        strConn &= "Data Source = c:/Northwind.mdb;"


        conn = New OleDbConnection(strConn)
        ds = New DataSet
        da = New OleDbDataAdapter("Select * from Products", conn)
        Try
            da.Fill(ds, "Products")
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
        DataGridView1.DataSource = ds.Tables("Products")
    End Sub

原创粉丝点击