Q: Trouble accessing data using ODBC from SQL I am using MFC to retrieve data from a SQL data source using ODBC.
I am having problem in getting data fields other than the "id" field in the  table.
The varValue is found to be null for the fields other than "id", in sunsequent iterations.
Please guide me in accessing all the data fields in the table
Table data: 

     **id**(nchar)     name(varchar)     age(varchar)

0    **11**                 john            24
1    **22**                 troy            25
2    **33**                 bill            21


only ids are fetched.


    CDatabase db;
    db.OpenEx( NULL, CDatabase::forceOdbcDialog );
    CRecordset rs( &db );
    rs.Open( CRecordset::forwardOnly,
             _T( "SELECT * FROM REPDB.dbo.fellas" ) );

CDBVariant varValue;

short nFields = rs.GetODBCFieldCount( );
while( !rs.IsEOF( ) )
{
   for( short index = 0; index < nFields; index++ )
   {
      rs.GetFieldValue( index, varValue,DEFAULT_FIELD_TYPE );
   }
}

Thanks.

A: This is a guess: the issue may be with DEFAULT_FIELD_TYPE. Using a plain CRecordset, the ODBC API may not be able to determine the type of the field. You can try omitting that parameter and see if you get char array representations of all of the fields, or use SQL_C_CHAR instead of DEFAULT_FIELD_TYPE, since all of your fields are string types.
You are also missing a call to rs.MoveNext at the end of the while loop.
Another possibility is the use of the cursor library: see this note on the GetFieldValue MSDN page:

Note: If you declare a recordset object
  without deriving from CRecordset, do
  not have the ODBC Cursor Library
  loaded. The cursor library requires
  that the recordset have at least one
  bound column; however, when you use
  CRecordset directly, none of the
  columns are bound. The member
  functions CDatabase::OpenEx and
  CDatabase::Open control whether the
  cursor library will be loaded.

