0

I am trying to use listboxes to categorize data and I am trying to use SQL to do so.

form picture

that link is what the form looks like know and what i'm trying to do - to use the listboxes to view the records by student year.

For the first list box here is the code for the first listbox to sort the data by year:

Imports System.Data.OleDb

Public Class viewStudent

Private Sub viewStudent_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'TODO: This line of code loads data into the 'ProjDataSet1.Details' table. You can move, or remove it, as needed.
    Me.DetailsTableAdapter1.Fill(Me.ProjDataSet1.Details)
    ' OleDbDataAdapter1.Fill(DataSet11)
End Sub

Private Sub lstYear_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstYear.SelectedIndexChanged
    Dim Year, SQLString As String
    Dim dtDetails As New DataTable()
    Dim dbDataAdapter As OleDbDataAdapter
    Dim ConnectString As String = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source = proj.accdb"
    Year = lstYear.Text
    SQLString = "SELECT * FROM Details WHERE Year = " & "'" _
        & Year & "'" & ""
    dbDataAdapter = New OleDbDataAdapter(SQLString, ConnectString)
    dbDataAdapter.Fill(dtDetails)
    grdRecords.DataSource = dtDetails
End Sub
End Class

But i get the error in the link below:

error

Can someone help to fix this? Thank you!

ɐsɹǝʌ ǝɔıʌ
  • 4,440
  • 3
  • 35
  • 56
Sohs
  • 27
  • 1
  • 8

1 Answers1

2

The "Microsoft.Jet.OLEDB.4.0" provider is the older 32-bit provider that can only work with .mdb database files. To work with an .accdb database you need to use the newer "Microsoft.ACE.OLEDB.12.0" provider.

Since you have the 64-bit version of Access 2013 installed you already have the 64-bit version of the ACE provider. All you need to do is

  1. Modify the properties of your .NET project to run as a 64-bit application (ref: here), and

  2. Change the connection string in your code to use Provider=Microsoft.ACE.OLEDB.12.0.

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418