How to read Access Table row by row? 
Author Message
 How to read Access Table row by row?

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



Fri, 01 Apr 2005 08:42:14 GMT  
 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



Fri, 01 Apr 2005 11:20:41 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. adding a table row, without setting same defaults as previous row

2. row heights of table rows added by vba

3. Err No rows at, duplicate table and row names

4. table row text will not show after row insert

5. View mdb tables rows by rows

6. Documentation - Read ( retrieve ) a single row from a Sql table

7. Extracting a row from a table using VB in Access 97

8. Need HaveDeleting Rows From an Access Table Using VB.Net Front End

9. How to change rows color in table and query using Access

10. Crosstable with rows from linked SQL and Access tables

11. Moveing rows from table to table

12. group every 8 rows in 1 row

 

 
Powered by phpBB® Forum Software