I'm trying to import all data from an Access DB using Visual Basic 2005. I'm new to Access and so far I can only import one record at a time. Any help would be appreciated!! Here is the code I have so far (obviously to bring one record at a time).

Private Sub BtnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xLoadButton.Click
Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String

'Connect to Access 2007
con.ConnectionString = "Provider = Microsoft.ACE.OLEDB.12.0; Data " & "Source = C:\Users\hp\Documents\Database1.accdb"

con.Open()

sql = "SELECT * FROM table1"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "Table1")
'The DataSet (ds) will now be filled with the records selected from table


MsgBox("A Connection to the Database is now open")
'close database connection
con.Close()

MsgBox("The Connection to the Database is now Closed")
xPartNumberCombobox.Text = ds.Tables("table1").Rows(0).Item(1)
xPartNameComboBox.Text = ds.Tables("table1").Rows(0).Item(2)
'***************************************************************************
xPartNumberCombobox.Show()
xPartNameComboBox.Show()
xLoadButton.hide()
End Sub

Hi
You want all the Rows from the database table returned not just Row 0?

(that was a pretty big hint BTW)

xPartNumberCombobox.Text = ds.Tables("table1").Rows(all).Item(all)?? So do I use all as the index?? What do i set all to after i declare it?

hi
You're getting close..

You have to loop through the values:

dim i as integer
dim DT as datatable
dim DR as Datarow 

'I'm just using DT and DR as I hate having to type out dataset.tables.rows...

DT = ds.Tables("Table1")
'VB uses a zero based index and Count is an actual count therefore we start a zero and end at count-1
for i =0 to DT.Rows.count -1
  DR = DT.Rows(i)
  xPartNumberComboBox.items.add(DR.item(0))
  xPartNameComboBox.items.add(DR.item(1))
next

I suggest you look up using loops in VB.NET

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.