Slowdown databinding

R

RvGrah

This code:

private void GetPlans(){
dt = dt.Clone(); //New object?
cn.Open();
SqlDataReader drd = cmdGetPlans.ExecuteReader();
if (drd.HasRows){
while (drd.Read()){
dt.Rows.Add(new Object[] {drd["JobID"].ToString(),//where the problem
happens
drd["CustName"].ToString()});
}
}
cn.Close();
}

Works instantly, but this code (Only the second line is different):

private void GetPlans(){
dt.Rows.Clear();
cn.Open();
SqlDataReader drd = cmdGetPlans.ExecuteReader();
if (drd.HasRows){
while (drd.Read()){
dt.Rows.Add(new Object[] {drd["JobID"].ToString(),
drd["CustName"].ToString()});
}
}
cn.Close();
}

Takes an eternal seeming 1.75 seconds to fill the first row the 2nd
time it's called.
Behavior is the same if I use a SqlDtaAdapter and DataSet. Only the
second time is that slow, the first call and all subsequent calls are
virtually instantaneous.

dt is a DataTable and is bound to a ComboBox(this is a critical part of
the problem) The sitution is the same databinding a dataset table to a
listbox, combobox or other like objects, or even just adding them from
a sqldatareader manually.


Can anyone tell me why?

TIA Bob Graham
 
C

Chad Z. Hower aka Kudzu

RvGrah said:
if (drd.HasRows){

This line is not needed BTW. If there are not rows, read will return false anyways. In fact some
DB's cannot even detect if there are rows or not in their provider until you call read and simply
always return true for HasRows.
dt is a DataTable and is bound to a ComboBox(this is a critical part of
the problem) The sitution is the same databinding a dataset table to a
listbox, combobox or other like objects, or even just adding them from
a sqldatareader manually.

There is a call, BeginUpdates or something like that. Try calling that before clear and dont foret to
call the end call too.


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Develop ASP.NET applications easier and in less time:
http://www.atozed.com/IntraWeb/
 
R

RvGrah

I've tried adding the items directly to a listbox, using
ListBox.BeginUpdate() and EndUpdate as well as many other methods, but
it seems any method where you fill or databind a combo or listbox from
a datasource the second time has this giant pause.

First and third and all other subsequent fills go fine, it's only the
second one that has a delay.

On Monday, I'll try to build a super minisample using northwind or pubs
sample database and see if I can test and demonstrate the problem
without any of the other overhead I have in my app.

Thanks for your reply

Bob
 

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