Home » VB.NetRSS

Populate a DatagridView from an Access Database

Hello

I have an application in which I have to populate a datagridview from one table from an access database. Here is the code that I use to open and close .mdb file.

 

 

Public sql AsString
Public mydb AsObject
Public mylist AsObject
Public LOCATION_DB AsStringApplication.StartupPath() & "\training_plann_db.mdb"

mydb = CreateObject(

 

"ADODB.Connection")
mydb.Open(
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + LOCATION_DB + ";Jet Oledb:Database Password=lupucpr;")
sql =
" select * from employee_table "
mylist = mydb.execute(sql)
Me.dgv_empl.DataSource = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ?????

mydb.close()

So, my question is, how can I populate dgv in this moment?
Can somebody help me, please?

I know that a way to populate is one by one in this way:
...

While mylist.eof=false
'''''' thing that will fill the row in datagridview'''
mylist.movenext
Wend

... But I don't want to use this way... I want a different way with a dataset or... I don't know.

 

2 Answers Found

 

Answer 1

A guess ...

Me.dgv_empl.DataSource = mylist

Hope this helps.

 

Answer 2

Here is code  I have used:

http://msmvps.com/blogs/deborahk/archive/2009/08/25/retrieve-a-datatable-using-microsoft-access.aspx

Then you would bind like this:

Me.dgv_empl.DataSource = dt

Hope this helps.

 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter