|
-
Mar 16th, 2004, 07:30 PM
#1
Thread Starter
Member
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:
Dim SelectQuery As String = "SELECT * FROM EntireLogbook"
Dim OleDbConnection As New OleDbConnection(ConnString)
Dim OleDbCommand As New OleDbCommand(SelectQuery, OleDbConnection)
Dim OleDbDataReader As OleDbDataReader
[COLOR=red]prbLoadProgress.Maximum = ????[/COLOR]
OleDbDataReader = OleDbCommand.ExecuteReader
prbLoadProgress.Visible = True
While OleDbDataReader.Read
Dim lviNewRecord as new ListViewItem()
[COLOR=green]'Adding subitems to listviewitem[/COLOR]
lstSequence.Items.Add(lviNewRecord)
prbLoadProgress.Value +=1
End While
prbLoadProgress.Visible = False
OleDbDataRreader.Close
OleDbConnection.Close
Last edited by WannabePBA; Mar 17th, 2004 at 12:23 PM.
-
Mar 17th, 2004, 08:28 AM
#2
How about
Recordset.RecordCount
?
I don't live here any more.
-
Mar 17th, 2004, 10:19 AM
#3
Thread Starter
Member
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.
-
Mar 17th, 2004, 10:22 AM
#4
Fanatic Member
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.
-
Mar 17th, 2004, 12:23 PM
#5
Thread Starter
Member
Counting records from an access database (RESOLVED)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|