CDatabase db;
db.ExecuteSQL("select * from title");
请问我在哪儿能调用我select的结果?
他们是以什么结构储存的?

解决方案 »

  1.   

    // Create and open a database object;
    // do not load the cursor library
    CDatabase db;
    db.OpenEx( NULL, CDatabase::forceOdbcDialog );// 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 SomeTable" ) );// 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
       }
       rs.MoveNext( );
    }rs.Close( );
    db.Close( );
      

  2.   

    谢谢
    看懂拉。
    一个重要的题外问题:
    我在看上面的程序的时候,在MSDN上找到拉这个例子。
    我想请问 ArrowHead(ArrowHead) ( ) 
    你是怎么会找到他的?
    谢谢
      

  3.   

    Using key word "CRecordset" and under "GetFieldValue"
      

  4.   

    不能用CDatabase,这个是执行没有返回值得,你用CRecordset
      

  5.   

    再请问,
    short nFields = rs.GetODBCFieldCount( );
    是得到选择的列数。
    哪个函数能得到选择的行数呢?
    我用GetRowsFetched();总是为1;