2014-03-25 62 views
0

我的代碼有什麼問題嗎? 我想補充,更新和使用VB13錯誤:「Microsoft.Jet.Oledb.4.0」提供程序未在本地計算機上註冊

這裏刪除數據庫中是我的代碼

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 
+0

'da.Fill(dt)'將負責在需要時打開連接。它將使.ConnectionState與它被調用之前相同。你真的不應該在開放狀態下離開一個連接;) –

+0

只是谷歌錯誤消息的*噸*命中,告訴你關於這個問題。你*必須正確拼寫,公司被稱爲「微軟」。 –

+0

這個問題似乎是無關緊要的,因爲許多其他網站已經提供了答案。 –

回答

1

這錯誤通常是在64位進程中運行你的應用程序的結果,而噴氣OLE DB提供程序僅作爲32位庫存在。如果您想在64位機器上使用Jet,那麼您必須確保您的應用程序在32位進程中運行。通過將項目屬性中的目標平臺設置爲x86或者(如果可用)將其設置爲默認Any CPU並檢查首選32位框,可以實現這一點。無論操作系統是32位還是64位,您的應用程序都將在所有機器上以32位進程運行。

相關問題