By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,838 Members | 1,675 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,838 IT Pros & Developers. It's quick & easy.

Datagrid display records too slow

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
<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

P: n/a
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.