Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When trying to use my VB.Net application to connect to accdb file that was originally converted from mdb using MS Access it the application gave me Unrecognized database format however when reversing the action and use the original mdb file it works normally also the migrated accdb file is accessible normally using MS Access

What I have tried:

Private Sub FillCustDataGrid()
    Try
        Dim sqlQRY As String
        sqlQRY = "Select * From Customers WHERE DateAdded >= #" + Today + "#"
        Dim da As OleDbDataAdapter
        Dim ds As DataSet = New DataSet
        da = New OleDbDataAdapter(sqlQRY, cnnOLEDB)
        Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(da)
        da.Fill(ds, "Customers")
        DataGridViewCustomer.DataSource = ds
        DataGridViewCustomer.DataMember = "Customers"
        lbl_RowCount.Text = DataGridViewCustomer.RowCount
        Dim row As Integer
        If DataGridViewCustomer.RowCount > 0 Then
            row = DataGridViewCustomer.FirstDisplayedCell.RowIndex
            DataGridViewCustomer.Rows(row).Selected = True
            DataGridViewCustomer.Sort(DataGridViewCustomer.Columns(6), ListSortDirection.Ascending)
            If RowIndex_Cust_TXT.Text = vbNullString Then
                Exit Sub
            Else
                Me.DataGridViewCustomer.ClearSelection()
                Me.DataGridViewCustomer.Rows(RowIndex_Cust_TXT.Text).Selected = True
                Me.DataGridViewCustomer.FirstDisplayedScrollingRowIndex = RowIndex_Cust_TXT.Text
            End If
        Else
            row = 0
        End If
    Catch ex As OleDbException
        MessageBox.Show(ex.Message)
    End Try
End Sub
Posted
Updated 16-Sep-19 23:20pm
Comments
Richard Deeming 17-Sep-19 13:30pm    
sqlQRY = "Select * From Customers WHERE DateAdded >= #" + Today + "#"

Don't do it like that!

In this specific case, since the parameter is a date, you might get away with it. But using string concatenation to build database queries can and will lead to SQL Injection[^] vulnerabilities.

Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]

Const sqlQRY As String = "Select * From Customers WHERE DateAdded >= ?"
Dim da As New OleDbDataAdapter(sqlQRY, cnnOLEDB)
da.SelectCommand.Parameters.AddWithValue("@p0", Today)

You most likely need to upgrade to the latest Access DB engine: Download Microsoft Access Database Engine 2016 Redistributable from Official Microsoft Download Center[^].
 
Share this answer
 
Comments
Maciej Los 17-Sep-19 5:12am    
5ed!
In addition to solution #1 by Richard MacCutchan[^] you'll need to change connection string. See: Access connection strings - ConnectionStrings.com[^]
 
Share this answer
 
Comments
BassamKassem 17-Sep-19 10:50am    
your solution is working with some users that have Microsoft office 32bit as for those whom having 64 it gave them error "the microsoft.ace.oledb.12.0 provider is not registered on local machine"

and the problem is that this application is added to shared folder with multiple users some have MS office 32 and others have 64bit version . so any help with that to make it universal with all kind of versions

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900