2014-03-25 2 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

이 문제에 대해 알려주는 히트 수 * 톤 *에 대한 오류 메시지를 Google에 보내면됩니다. 당신은 그것을 올바르게 철자해야만합니다. 회사는 "Microsoft"라고 불립니다. –

+0

이 질문은 답변이 이미 다른 많은 웹 사이트에서 제공 되었기 때문에 논제가 아닌 것 같습니다. –

답변

1

그 오류는 일반적으로 64 비트 프로세스에서 실행중인 응용 프로그램의 결과 인 제트 OLE DB 동안 공급자는 32 비트 라이브러리로만 존재합니다. 64 비트 컴퓨터에서 Jet를 사용하려면 응용 프로그램이 32 비트 프로세스에서 실행되는지 확인해야합니다. 프로젝트 속성의 대상 플랫폼을 x86으로 설정하거나 가능하다면 기본 모든 CPU로 설정하고 선호 32 비트 상자를 선택하십시오. OS가 32 비트인지 64 비트인지에 상관없이 앱은 모든 머신에서 32 비트 프로세스로 실행됩니다.

관련 문제