VERY SLOW EXECUTION - VC# APPLICATION with MS SQL 2000

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mathewphilipp
    New Member
    • Feb 2007
    • 7

    VERY SLOW EXECUTION - VC# APPLICATION with MS SQL 2000

    Dear all,
    I have a VC# (winforms) application written in Visual studio 2003 with .Net framework 1.1, here I want to populate 6 listboxes with bulk amount of data ( Eg. combox A and B each with 20000 items , combobox C and D each with 4500 items , combox E and F each with 100 items). I am using a stored procedure here , Please see the following example ( other stored proceduers and code blocks are also same but having differnt names) it takes around 40 Minuts to load the form with populated controls....!!! !!

    /* SP */
    CREATE PROCEDURE sp_name AS
    begin
    select id,name from tableName order by name
    end
    GO

    /* VC# code */
    SqlCommand m_CMD = new SqlCommand("sp_ name",m_con); // EXECUTING STORED PROCEDURE TO LOAD ITEMS

    m_CMD.CommandTy pe = CommandType.Sto redProcedure;

    m_con.Open();

    SqlDataReader m_dr ;

    m_dr = m_CMD.ExecuteRe ader();

    while (m_dr.Read())

    {

    lb_ID.Items.Add (m_dr.GetValue( 0).ToString());

    lb_Name.Items.A dd(m_dr.GetValu e(1).ToString() );

    }

    m_dr.Close();

    m_con.Close();

    /* Code ends */

    I want to optimize the code, Any body having Idea ?
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Use a DataAdapter to fill a DataTable (or DataSet) and then use the DataSource property to populate your comboboxes.

    Although 4500 is a bit excessive....wh o's gonna want to sift through that?

    Comment

    • mathewphilipp
      New Member
      • Feb 2007
      • 7

      #3
      Originally posted by Plater
      Use a DataAdapter to fill a DataTable (or DataSet) and then use the DataSource property to populate your comboboxes.

      Although 4500 is a bit excessive....wh o's gonna want to sift through that?
      According to me 4500 is lesser i have to load 20000 each in 2 list boxes, its loading in a kool manner, Only problem is time consuming around 25 minutes it takes. its a must to load all the items.. Data adaptor and datatable combination is already used it takes more time than that of reader

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Well I'm not sure what to tell you except to try and find a way to split it up.
        A good rule of thumb is no more then a couple dozen entries (say 50?) in a dropdrown.
        That's a number out of hat, but you should be able to do a limiting thing.
        We have a page that has a dropdown of a potential 18,000 different items. However we don't load the oldest 9,000 unless required too.

        Comment

        • mathewphilipp
          New Member
          • Feb 2007
          • 7

          #5
          Hello,

          I am solved the issue by binding the datatable directly to the control. Now I am not using any loop. Loop made it slow.

          Thanks

          Mathew Philip

          Comment

          Working...