Too slow to use datagrid display records

K

Kai Zhang

I am trying to display some database records in datagrid using dataset.

the records need to be displayed are couple of thousands, but the records in
database that the SQL query needs to exam are more than 70 thousand, and it
is really slow to get the dataset ready to populate the datagrid.

I am sure there are solutions on this issue, but I just don't know :-(

Can anybody point me out any good solution to minimize the time used to
populate the datagrid?

Thanks a lot!

One thing I thought of is to make the datagrid starts to display records
simultaneously when data is filling into dataset. but I am not sure how to
achieve that.
 
K

Kai Zhang

Thanks for your reply, Ken.

for the first link:
http://www.vb-tips.com/default.aspx?ID=49f2cff5-56ad-44fc-a4c6-fc0d5c470f53
It allows user to know how much records have been loaded, and how long it
may take to finish loading the records, however, it does not allow user to
view the records quicker (unless update "Datagrid.DataSource" while
Datareader is reading records which may be very nasty, but I will have a
try).

for the second link:
http://www.vb-tips.com/default.aspx?ID=79afdb6a-611d-43cd-9186-def86a1baeef
I am using the SQL 2000, so I cannot use this approach unless I implement
the NTile() by myself.
 
K

Kai Zhang

Hi Ken,
I did some changes to the sample code you suggested me to read on link:
http://www.vb-tips.com/default.aspx?ID=49f2cff5-56ad-44fc-a4c6-fc0d5c470f53

Here is my code:
...
dgbase.DataSource = table 'dgbase is the datagrid,
'table is a DataTable
which already has columns
While reader.Read 'reader is a SqlDataReader
Dim row As DataRow
row = table.NewRow()

Dim tempObject(table.Columns.Count - 1) As Object
reader.GetValues(tempObject)
row.ItemArray = tempObject

table.Rows.Add(row) 'Add new row to dgbase.DataSource
dgbase.Refresh() 'show the new added row
End While
...

The above code works fine, except all the controls on the form do not
respond to any interaction while the records is loaded into datagrid.

I know I can solve this by using a separate thread to run the above code,
and I am working on it. hopefully it will be OK.

Thanks again, Ken.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top