471,605 Members | 1,595 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,605 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 2847
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by VM | last post: by
5 posts views Thread by John Richardson | last post: by
3 posts views Thread by Jennyfer J Barco | last post: by
6 posts views Thread by Ron L | last post: by
3 posts views Thread by Kai Zhang | last post: by
reply views Thread by latin & geek via DotNetMonster.com | last post: by
3 posts views Thread by archana | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by MichaelMortimer | last post: by
reply views Thread by CCCYYYY | last post: by

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.