Results 1 to 5 of 5

Thread: Counting rows in an access database (RESOLVED)

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2004
    Location
    Miami FL
    Posts
    38

    Counting rows in an access database (RESOLVED)

    Hello. I would like to know if there is any way to get the number of rows in an access database. I want to do something where I connect to an access database and read through the rows and add each row to a listview control. The database will eventually get very large, so I want to use a progress bar to let the user know how much longer it is going to take. So I want the project to get the number of rows in the data base, then I will set the maximum of the progress bar to that number. While looping through each record, I will add 1 to the value property of the progress bar, thereby moving the progress bar to the right until the datareader is finished. Here is my code. I will highlight the line of code that I am missing/don't know how to do.

    VB Code:
    1. Dim SelectQuery As String = "SELECT * FROM EntireLogbook"
    2. Dim OleDbConnection As New OleDbConnection(ConnString)
    3. Dim OleDbCommand As New OleDbCommand(SelectQuery, OleDbConnection)
    4. Dim OleDbDataReader As OleDbDataReader
    5.  
    6. [COLOR=red]prbLoadProgress.Maximum = ????[/COLOR]
    7.  
    8. OleDbDataReader = OleDbCommand.ExecuteReader
    9. prbLoadProgress.Visible = True
    10. While OleDbDataReader.Read
    11.      Dim lviNewRecord as new ListViewItem()
    12.      [COLOR=green]'Adding subitems to listviewitem[/COLOR]
    13.      lstSequence.Items.Add(lviNewRecord)
    14.      prbLoadProgress.Value +=1
    15. End While
    16. prbLoadProgress.Visible = False
    17. OleDbDataRreader.Close
    18. OleDbConnection.Close
    Last edited by WannabePBA; Mar 17th, 2004 at 12:23 PM.

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    How about

    Recordset.RecordCount

    ?
    I don't live here any more.

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2004
    Location
    Miami FL
    Posts
    38
    But that doesn't work with an access database does it? I don't load the database into a recordset, I just read directly from access.

  4. #4
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    you'll have to use an sql string of something like "select count(ID) from tablename"

    and use the executescalar method of oledbcommand object


    That's unless you want to use a dataset instead of a datareader as dataset has myDataset.tables(0).rows.count.
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2004
    Location
    Miami FL
    Posts
    38

    Counting records from an access database (RESOLVED)

    PERFECT! Thanks a lot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width