Here is a little bit modified test and a picture of the "table".
The output isCode:// 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: %s Age: %u\n", strName, nAge); rs.MoveNext(); } } CATCH_ALL(e) { e->ReportError(); } END_CATCH_ALL
Code:Name: John Age: 23 Name: Mary Age: 45 Name: Bob Age: 34
And again: DAO is deprecated!
See Compiler warning C4995.
.




Reply With Quote