CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Fast Query

  1. #1
    Join Date
    May 2003
    Location
    Turku/Finland
    Posts
    77

    Fast Query

    Is possible make faster query ?
    I have follow code and this is slow.
    Different system ?


    CString Day= "20040524";
    CString Period1 ="Other1";
    CString Period2 ="Other2";

    m_pSet->Close();
    m_pSet->m_strFilter.Format(" COL1 > '%s' AND COL2 <> '%s' AND COL3 <> '%s'" ,Day,Period1 ,Period2);
    m_pSet->Open();

    int recCount = m_pSet->GetRecordCount();
    if (recCount == 0){
    m_pSet->Close();
    m_pSet->m_strFilter = "";
    m_pSet->Open();
    nFields = 0;
    m_list.DeleteAllItems();}
    else { int ii = 0;
    }

    while ( !m_pSet->IsEOF( ) ){

    m_pSet->GetFieldValue(("COL1"), CDay);
    m_list.InsertItem(ii, CDay);

    m_pSet->GetFieldValue(("COL2"), CPeriod1);
    m_list.SetItemText(ii, 1, CPeriod1);

    m_pSet->GetFieldValue(("COL3"), CPeriod2);
    m_list.SetItemText(ii, 2, CPeriod2);

    m_pSet->GetFieldValue(("COL4"), CPeriod3);
    m_list.SetItemText(ii, 3, CPeriod3);

    UpdateData(FALSE);
    m_pSet->MoveNext();}

  2. #2
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125
    If you want any type of performance, do NOT use alpha column lookups within the loop....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  3. #3
    Join Date
    May 2003
    Location
    Turku/Finland
    Posts
    77
    i'm stupid, could you elaborate ?

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635
    Documentation for GetRecordCount says you have to actually read the records. Just calling it after an open won't work. Test for IsEOF() instead. Other than that, just make sure the fields you're querying are indexed. Also, if it's a big table, a dynaset may run quicker than a snapshot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured