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

Threaded View

  1. #3
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: Unable to read numeric values from Excel file using CDaoRecordset

    Here is a little bit modified test and a picture of the "table".
    Code:
        // just for testing purpose
        TRY 
        {
            CDatabase dbb;
            CDaoDatabase db;
            db.Open(_T("c:\\test.xls"), FALSE, FALSE, _T("Excel 5.0;"));
            CDaoRecordset rs(&db);
            rs.Open(AFX_DAO_USE_DEFAULT_TYPE, _T("SELECT Name, Age FROM [Sheet1$]"));
            while(!rs.IsEOF())
            {
                COleVariant vtName, vtAge;
                rs.GetFieldValue(_T("Name"), vtName);
                rs.GetFieldValue(_T("Age"), vtAge);
                CString strName = vtName.bstrVal;
                UINT nAge = static_cast<UINT>(vtAge.dblVal);
                TRACE2("Name: &#37;s  Age: %u\n", strName, nAge);
                rs.MoveNext();
            }
        }
        CATCH_ALL(e)
        {
            e->ReportError();
        }
        END_CATCH_ALL
    The output is
    Code:
    Name: John  Age: 23
    Name: Mary  Age: 45
    Name: Bob  Age: 34

    And again: DAO is deprecated!
    See Compiler warning C4995.

    .
    Attached Images Attached Images
    Last edited by ovidiucucu; June 2nd, 2010 at 11:28 AM.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

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