CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2010
    Posts
    22

    how to order records in ACCESS by MFC objects like CDaodatabase or CDaoRecordset?

    table with primary key already set-down in ACCESS. when insert records into the table by Execute() function of cdaodatabase, to some extense, the records are not put behind the last record as wished, otherwise randomly into other places!

    now i want to do some kind of operation to order the table after insertion by cdaodatabase or some others. how to?

    waiting for your help!!

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: how to order records in ACCESS by MFC objects like CDaodatabase or CDaoRecordset?

    If you look at the documentation for CDaoRecordset, I think you'll find a member with a pretty obvious name that does what you want.

  3. #3
    Join Date
    Mar 2010
    Posts
    22

    Re: how to order records in ACCESS by MFC objects like CDaodatabase or CDaoRecordset?

    in CDaoRecordset, with m_strSort member i can get the order records. but nothing changes in table! the code as follows,

    /*
    table aa: ind as the primary key
    /////////
    ind ind2
    21 111
    23 333
    24 444
    /////////
    */
    CDaoRecordset ret(&db);
    ret.m_strSort = _T("[ind] DESC");
    sql = _T("select * from aa");
    ret.Open(dbOpenDynaset,sql,0);
    COleVariant var,var1;
    // get the first record! with setting above surly the first record is (24 444)
    // but nothing changes with table aa: records ordered ascently!!
    ret.GetFieldValue(0,var);
    ret.GetFieldValue(1,var1);
    sql.Format(_T("%d, %d"),var.lVal, var1.lVal);
    GetDlgItem(IDC_SHOW)->SetWindowText(sql);
    ret.Close();

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: how to order records in ACCESS by MFC objects like CDaodatabase or CDaoRecordset?

    I've never used a CDaoRecordset, but it's possible your sql statement is overriding the m_strSort. Try adding ORDER BY to sql, or leaving sql NULl and using m_strFilter and m_strSort.

  5. #5
    Join Date
    Mar 2010
    Posts
    22

    Re: how to order records in ACCESS by MFC objects like CDaodatabase or CDaoRecordset?

    thanks for your help! i am trying to deal with it!!!

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