用下面的代码操作ODBC#include "afxdb.h"//---------------------------------------------------------------
// Create and open a database object;
// do not load the cursor library
CDatabase db;
//db.OpenEx( NULL, CDatabase::forceOdbcDialog );
db.OpenEx( "DSN=rsgl;UID=;PWD=", CDatabase::noOdbcDialog );// Create and open a recordset object
// directly from CRecordset. Note that a
// table must exist in a connected database.
// Use forwardOnly type recordset for best
// performance, since only MoveNext is required
CRecordset rs( &db );
rs.Open( CRecordset::forwardOnly,
        _T( "SELECT * FROM system_table" ) );// Create a CDBVariant object to
// store field data
CDBVariant varValue;// Loop through the recordset,
// using GetFieldValue and
// GetODBCFieldCount to retrieve
// data in all columns
short nFields = rs.GetODBCFieldCount( );
while( !rs.IsEOF( ) )
{
for( short index = 0; index < nFields; index++ )
{
rs.GetFieldValue( index, varValue );
// do something with varValue
AfxMessageBox(*varValue.m_pstring);
}
rs.MoveNext( );
}rs.Close( );
db.Close( );
把上面的rsgl换成你的数据源名:test