错误:“Microsoft.Jet.Oledb.4.0”提供程序未在本地计算机上注册
Posted
技术标签:
【中文标题】错误:“Microsoft.Jet.Oledb.4.0”提供程序未在本地计算机上注册【英文标题】:Error: The 'Microsoft.Jet.Oledb.4.0' provider is not registered on the local machine 【发布时间】:2014-03-25 22:06:13 【问题描述】:我的代码有什么问题吗? 我想使用 vb13 在数据库中添加、更新和删除
这是我的代码
Public Class Form1
Dim cnn As New OleDb.OleDbConnection
Private Sub cmdexit_Click(sender As Object, e As EventArgs) Handles cmdexit.Click
Close()
End Sub
Private Sub cmdclear_Click(sender As Object, e As EventArgs) Handles cmdclear.Click
txtaddress.Text = ""
txtstdntid.Text = ""
txtstdntname.Text = ""
txttelephone.Text = ""
txtstdntid.Tag = ""
cmdedit.Enabled = True
cmdadd.Text = "Add"
txtstdntid.Focus()
End Sub
Private Sub RefreshData()
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
Dim da As New OleDb.OleDbDataAdapter("SELECT stdid as [ID], " & "stdname as [Name], Gender, Phone, Address " & "FROM student ORDER BY stdid", cnn)
Dim dt As New DataTable
da.Fill(dt)
DataGridView1.DataSource = dt
cnn.Close()
End Sub
Private Sub cmdadd_Click(sender As Object, e As EventArgs) Handles cmdadd.Click
Dim cmd As New OleDb.OleDbCommand
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
cmd.Connection = cnn
If txtstdntid.Tag & "" = "" Then
cmd.CommandText = "INSERT INTO Student(stdid, stdname, gender, phone, address) " & "VALUES(" & txtstdntid.Text & ",'" & txtstdntname.Text & "','" & Cmbgender.Text & "','" & txttelephone.Text & "','" & txtaddress.Text & "')"
cmd.ExecuteNonQuery()
Else
cmd.CommandText = "UPDATE student" & "SET stdid=" & txtstdntid.Text & ", stdname='" & txtstdntname.Text & "'" & ", gender='" & Cmbgender.Text & "'" & ", phone='" & txttelephone.Text & "'" & "WHERE stdid=" & txtstdntid.Tag
cmd.ExecuteNonQuery()
End If
RefreshData()
cmdclear.PerformClick()
cnn.Close()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
cnn = New OleDb.OleDbConnection
cnn.ConnectionString = "Provider=Mircosoft.Jet.Oledb.4.0; Data Source=" & Application.StartupPath & "\data.mdb"
RefreshData()
End Sub
Private Sub cmdedit_Click(sender As Object, e As EventArgs) Handles cmdedit.Click
If DataGridView1.Rows.Count > 0 Then
If DataGridView1.SelectedRows.Count > 0 Then
Dim intStdID As Integer = DataGridView1.SelectedRows(0).Cells("id").Value
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM student " & "WHERE stdid=" & intStdID, cnn)
Dim dt As New DataTable
da.Fill(dt)
txtstdntid.Text = intStdID
txtstdntname.Text = dt.Rows(0).Item("stdname")
Cmbgender.Text = dt.Rows(0).Item("gender")
txttelephone.Text = dt.Rows(0).Item("phone")
txtaddress.Text = dt.Rows(0).Item("address")
txtstdntid.Tag = intStdID
cmdadd.Text = "Update"
cmdedit.Enabled = False
cnn.Close()
End If
End If
End Sub
Private Sub cmddelete_Click(sender As Object, e As EventArgs) Handles cmddelete.Click
If DataGridView1.Rows.Count > 0 Then
If DataGridView1.SelectedRows.Count > 0 Then
Dim intStdID As Integer = DataGridView1.SelectedRows(0).Cells("id").Value
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
Dim cmd As New OleDb.OleDbCommand
cmd.Connection = cnn
cmd.CommandText = "DELETE FROM student WHERE stdid=" & intStdID
cmd.ExecuteNonQuery()
RefreshData()
cnn.Close()
End If
End If
End Sub
End Class
【问题讨论】:
da.Fill(dt)
将在需要时负责打开连接。它将使 .ConnectionState 与调用之前相同。你真的不应该让连接处于打开状态;)
只需用谷歌搜索错误消息,即可找到 吨 条告诉您有关此问题的点击。您确实必须正确拼写,该公司名为“Microsoft”。
这个问题似乎离题了,因为许多其他网站已经提供了答案。
【参考方案1】:
该错误通常是由于您的应用程序在 64 位进程中运行,而 Jet OLE DB 提供程序仅作为 32 位库存在。如果您想在 64 位机器上使用 Jet,那么您必须确保您的应用程序在 32 位进程中运行。您可以通过将项目属性中的 Target Platform 设置为 x86 来做到这一点,或者,如果可用,将其设置为默认的 Any CPU 并选中 Prefer 32-bit 框。然后,您的应用将在所有机器上以 32 位进程运行,无论操作系统是 32 位还是 64 位。
【讨论】:
以上是关于错误:“Microsoft.Jet.Oledb.4.0”提供程序未在本地计算机上注册的主要内容,如果未能解决你的问题,请参考以下文章
Microsoft.Jet.OLEDB.4.0 - 找不到提供程序。可能没有正确安装
未在本地计算机上注册“Microsoft.Jet.OleDb.4.0”提供程序。解决办法
04-OLE DB 访问接口 Microsoft.Jet.OLEDB.4.0 尚未注册的错误
(win10 64位)未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序