Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I want to import data from Access to my datagridview in VB.net
when i import, it is error like this:Could not find installable ISAM

I've installed the accessdatabaseengine & I've compile my program as a 32-bit program but it still didn't work

Here is my source code for import from excel to datagridview:

What I have tried:

VB
Private Sub frm_watercolour_A155751_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            
    Public myconnection As String = "Provider=Microsoft.ACE.OLEDB.12.0;DataSource=C:DB_ARTBOX.accdb;Persist Security Info=False;"
    
            Dim mysql As String = "SELECT * FROM TBL_PRODUCT where FLD_PRODUCT_CATEGORY = 'WATERCOLOUR' "
            Dim mydatatable As New DataTable
            Dim myreader As New OleDb.OleDbDataAdapter(mysql, myconnection)
            myreader.Fill(mydatatable)
            grd_watercolour.DataSource = mydatatable
        End Sub
Posted
Updated 15-Oct-16 2:52am
v2

Well...

A myconnection variable is type of String and stores connection string. Note: this is not OleDbConnection object! So, this line:
VB.NET
Dim myreader As New OleDb.OleDbDataAdapter(mysql, myconnection)

won't execute, as an OleDbDataAdapter[^] constructor accepts SelectCommand[^] and OleDbConnection.

To be able to get MS Access data, you have to:

  1. create OleDbConnection[^] then open it
  2. create OleDbCommand[^]
  3. create OleDbDataReader[^] and fill it by executing OleDbCommand[^]
  4. create DataTable[^] object and load[^] data into it
  5. release resources (for example: close OleDbConnection)


That's all!

For further details, please see:
Accessing Microsoft Office Data from .NET Applications[^]
Connect to data in an Access database (Windows Forms)[^] - recommended!
 
Share this answer
 
v2
Comments
Member 12794883 15-Oct-16 9:15am    
Thankyou! I'll try
Wendelius 15-Oct-16 11:48am    
Good points,5!
Maciej Los 15-Oct-16 16:25pm    
Thank you, Mika.
It looks like the path to the Access database is wrong. If the database file is located in the root direcory of drive C, try the following
VB
Public myconnection As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\DB_ARTBOX.accdb;Persist Security Info=False;"

Also note the space in Data Source
 
Share this answer
 
v2
Comments
Member 12794883 15-Oct-16 5:55am    
i've done what you've told but it still didnt work, it says 'coulnd not find file'
Wendelius 15-Oct-16 6:03am    
Is the path correct? Is the ACCDB file located in C:\ ?
Member 12794883 15-Oct-16 6:45am    
yup
Wendelius 15-Oct-16 7:11am    
Do you get the error message "Could not find file" when you connect to the database or when you execute an SQL command? If this happens when executing a command, what is the SQL statement?
Member 12794883 15-Oct-16 9:14am    
when I execute SQL command

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