用Crecordset如何读取SQL server表中Text类型的数据????
好象用一般的方法不能读取!!!期盼回复!!!

解决方案 »

  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 );
          unsigned char test1=rs.m_chVal;//Contains a value of type unsigned char.
          CString test2=m_pstring;//Contains a pointer to an object of type CString.
       }
       rs.MoveNext( );
    }rs.Close( );
    db.Close( );
      

  2.   

    可以,只需要在映射的类中注明TEXT的长度
    RFX_Text(pFX, _T("[UNITCODE]"), m_UnitCode, 2500); //2500就是长度。