
How to read Access Table row by row?
What type of control is Item_List? You are binding the recordset to its
datasource property and then you proceed to load the control manually.
Usually its one or the other (many prefer manual loading and avoid data
binding).
The recordset row never changes in the Do Loop and will never hit EOF. Use
the MoveNext method of the recordset object. Also, it looks like your Index
variable represents a row yet you are using it as an index to the Fields
collection. If Item_List is a multicolumn control then something like the
following pseudocode might help.
Open the Connection
Create the Recordset
Do Until recordSet EOF
Create a new row in the list control
For each Field in the Recordset Fields collection
Add Field value to the list control row
Next
Move to the next row in the recordset
Loop
Close the Connection
HTH
Bruce
Quote:
> Hi,
> I am new to Database programming. I made up a Database in
> Microsoft Access 2000 and the application gets connected
> to the Access file without problem. however, it reads item
> by item and returns an error of null character at the end
> of the first row. Is it possible to read row by row from
> the table until the end of the table?
> Dim DB_Connection As New ADODB.Connection
> Dim DB_RecordSet As New ADODB.Recordset
> Dim DB_String As String
> Private Sub Connect()
> Dim index As Integer
> DB_Connection.Open "Driver={Microsoft Access Driver
> (*.mdb)};" & _
> "Dbq=c:\DB.mdb;" & _
> "Uid=admin;" & _
> "Pwd="
> DB_String = "SELECT * FROM sortByRoom1001"
> DB_RecordSet.Open DB_String, DB_Connection
> Set Item_List.DataSource = DB_RecordSet
> index = 0
> Do Until DB_RecordSet.EOF
> Item_List.AddItem (DB_RecordSet.Fields(index))
> index = index + 1
> Loop
> DB_Connection.Close
> End Sub
> Thanks
> Elvin