473,387 Members | 1,463 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Datagrid display records too slow

In a winform I want to display database records using datagrid, with
dataset for a couple of thousands records it seems very slow. I have
read an article in group microsoft.public.dotnet.languages.vb. It uses
datareader to solve this problem, it's a good idea. I have translated
it in c# and want to run this in a separate thread, but it does not
work, i have a blank datagrid.

Anyone can help me? Thanks a lot.

My source code is following:

static private System.Threading.Thread m_pThread = null;

public void FillDataGrid()
{
DataTable dtList = dbman.GetOrderListSchema();
dataGrid_orderlist.DataSource = dtList;
SqlDataReader reader = dbman.GetOrderListPro();

while( reader.Read() )
{
DataRow dr = dtList.NewRow();
object[] tmp = new object[dtList.Columns.Count-1];
reader.GetValues(tmp);
dr.ItemArray = tmp;
dtList.Rows.Add(dr);
dataGrid_orderlist.Refresh();
}

reader.Close();
}

private void FormSearch_Load(object sender, System.EventArgs e)
{
m_pThread = new System.Threading.Thread(new
System.Threading.ThreadStart(FillDataGrid));
m_pThread.Name = "FillDataGrid";
m_pThread.IsBackground = true;
m_pThread.Start();
}

Jan 17 '06 #1
3 2936
Is the user legitimately going to need to see all couple of thousand records?
Why not put some filter controls on the form and let the user select what
they need, and use these as part of the WHERE SQL clause.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"qi****@hotmail.com" wrote:
In a winform I want to display database records using datagrid, with
dataset for a couple of thousands records it seems very slow. I have
read an article in group microsoft.public.dotnet.languages.vb. It uses
datareader to solve this problem, it's a good idea. I have translated
it in c# and want to run this in a separate thread, but it does not
work, i have a blank datagrid.

Anyone can help me? Thanks a lot.

My source code is following:

static private System.Threading.Thread m_pThread = null;

public void FillDataGrid()
{
DataTable dtList = dbman.GetOrderListSchema();
dataGrid_orderlist.DataSource = dtList;
SqlDataReader reader = dbman.GetOrderListPro();

while( reader.Read() )
{
DataRow dr = dtList.NewRow();
object[] tmp = new object[dtList.Columns.Count-1];
reader.GetValues(tmp);
dr.ItemArray = tmp;
dtList.Rows.Add(dr);
dataGrid_orderlist.Refresh();
}

reader.Close();
}

private void FormSearch_Load(object sender, System.EventArgs e)
{
m_pThread = new System.Threading.Thread(new
System.Threading.ThreadStart(FillDataGrid));
m_pThread.Name = "FillDataGrid";
m_pThread.IsBackground = true;
m_pThread.Start();
}

Jan 17 '06 #2
<qi****@hotmail.com> wrote:
In a winform I want to display database records using datagrid, with
dataset for a couple of thousands records it seems very slow. I have
read an article in group microsoft.public.dotnet.languages.vb. It uses
datareader to solve this problem, it's a good idea.
It's only a good idea if you've *proven* that it improves the
performance significantly. You should test each of them individually
(with nothing else happening, so in a console app).
I have translated
it in c# and want to run this in a separate thread, but it does not
work, i have a blank datagrid.

Anyone can help me? Thanks a lot.


Well for one thing, if your DataTable is bound in the UI you mustn't
change it from another thread, otherwise you'll trigger a refresh in
the wrong thread. You need to either create a new DataTable, fill that,
*then* bind to it, or pass the data back to the UI thread and fill the
DataTable up there.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 17 '06 #3
Hi, Peter,

as default if user do not give any condition all records should be
displayed. That is what I must do, I have no choice. :-(

Peter Bromberg [C# MVP] schrieb:
Is the user legitimately going to need to see all couple of thousand records?
Why not put some filter controls on the form and let the user select what
they need, and use these as part of the WHERE SQL clause.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"qi****@hotmail.com" wrote:
In a winform I want to display database records using datagrid, with
dataset for a couple of thousands records it seems very slow. I have
read an article in group microsoft.public.dotnet.languages.vb. It uses
datareader to solve this problem, it's a good idea. I have translated
it in c# and want to run this in a separate thread, but it does not
work, i have a blank datagrid.

Anyone can help me? Thanks a lot.

My source code is following:

static private System.Threading.Thread m_pThread = null;

public void FillDataGrid()
{
DataTable dtList = dbman.GetOrderListSchema();
dataGrid_orderlist.DataSource = dtList;
SqlDataReader reader = dbman.GetOrderListPro();

while( reader.Read() )
{
DataRow dr = dtList.NewRow();
object[] tmp = new object[dtList.Columns.Count-1];
reader.GetValues(tmp);
dr.ItemArray = tmp;
dtList.Rows.Add(dr);
dataGrid_orderlist.Refresh();
}

reader.Close();
}

private void FormSearch_Load(object sender, System.EventArgs e)
{
m_pThread = new System.Threading.Thread(new
System.Threading.ThreadStart(FillDataGrid));
m_pThread.Name = "FillDataGrid";
m_pThread.IsBackground = true;
m_pThread.Start();
}


Jan 18 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: VM | last post by:
I have a 35000 line datagrid and updating one field in all 35000 rows takes an eternity. How come? Since I don't have the datasource available (it may be a table or view), in my example I do it...
2
by: VM | last post by:
When I display data to a Windows datagrid I usually fill the underlying table (in another class) and then, once it contains all the data, I attach it to the grid. But there are some processes that...
5
by: John Richardson | last post by:
I've been bothered for some time about my DataGrid not populating my rows very quickly. I have about 10K rows loading into the grid. I create a datatable dt with 2 columns, an ID and a display. ...
3
by: Jennyfer J Barco | last post by:
In my application I have a datagrid. The code calls a Stored procedure and brings like 200 records. I created a dataset and then a dataview to bind the results of the query to my grid using ...
6
by: Ron L | last post by:
I have a dataset whose source is a SQL 2k stored procedure that I am trying to display in a datagrid. This datasource has 4 columns that I am interested in here, a text column and 3 value columns...
1
by: jwogick | last post by:
I'm hoping someone can help me! I just have a simple form with a datagrid displaying child records from a dataset that contains two related tables Parent table>Clients Child table>cases. using the...
3
by: Kai Zhang | last post by:
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...
0
by: latin & geek via DotNetMonster.com | last post by:
hi! ok, im working on a database application. ive successfully managed to establish a relationship between two tables and display them on a datagrid, edit and add new records to them. now i...
3
by: archana | last post by:
Hi all, Can anyone tell me what exactly VirtualItemCount in datagrid. I read on msdn but not clear about it. Any help will be truely appreciared. thanks in advance
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.