Slowdown databinding

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RvGrah

    Slowdown databinding

    This code:

    private void GetPlans(){
    dt = dt.Clone(); //New object?
    cn.Open();
    SqlDataReader drd = cmdGetPlans.Exe cuteReader();
    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.Exe cuteReader();
    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

  • Chad Z. Hower aka Kudzu

    #2
    Re: Slowdown databinding

    "RvGrah" <rvgrahamsevate nein@sbcglobal. net> wrote in news:1119022019 .703508.195840
    @o13g2000cwo.go oglegroups.com:[color=blue]
    > if (drd.HasRows){[/color]

    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.
    [color=blue]
    > 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.[/color]

    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/
    "Programmin g is an art form that fights back"

    Develop ASP.NET applications easier and in less time:

    Comment

    • RvGrah

      #3
      Re: Slowdown databinding

      I've tried adding the items directly to a listbox, using
      ListBox.BeginUp date() 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

      Comment

      Working...