主要是GetFieldValue问题,如果读取数字的话,他的类型就要定义为CDBVariant。但是我不知道这种类型以后如何赋值,如何与int类型的变量比较以及如何输出。请各位高手指教一下,如果有更好的读取数据库的函数也介绍一下,谢谢!!!!!!!

解决方案 »

  1.   

    CDBVariant 是一个MFC ODBC class,先定义一个实例,然后使用m_iVal就可以了.m_dwType    Contains the data type of the currently stored value. Type DWORD. 
    m_boolVal   Contains a value of type BOOL. 
    m_chVal     Contains a value of type unsigned char. 
    m_iVal      Contains a value of type short. 
    m_lVal      Contains a value of type long. 
    m_fltVal    Contains a value of type float. 
    m_dblVal    Contains a value of type double. 
    m_pdate     Contains a pointer to an object of type TIMESTAMP_STRUCT. 
    m_pstring   Contains a pointer to an object of type CString. 
    m_pbinary   Contains a pointer to an object of type CLongBinary 
      

  2.   

    CDBVariant 是一个MFC ODBC class,先定义一个实例,然后使用m_iVal就可以了.m_dwType    Contains the data type of the currently stored value. Type DWORD. 
    m_boolVal   Contains a value of type BOOL. 
    m_chVal     Contains a value of type unsigned char. 
    m_iVal      Contains a value of type short. 
    m_lVal      Contains a value of type long. 
    m_fltVal    Contains a value of type float. 
    m_dblVal    Contains a value of type double. 
    m_pdate     Contains a pointer to an object of type TIMESTAMP_STRUCT. 
    m_pstring   Contains a pointer to an object of type CString. 
    m_pbinary   Contains a pointer to an object of type CLongBinary 
      

  3.   

    访问Access最好用ADO,至不济用DAO也可以,用ODBC是最下策了。至于CDBVariant或者COleVariant等类型,都是一个联合数据结构,只要给相应类型的成员赋值和读取就可以了。
      

  4.   

    数据库的动态连接:(需要不少DLL支持的;大概有14个左右); 
    AfxOleInit();///初始化COM库 HRESULT hr; 
    hr=m_pConnection.CreateInstance("ADODB.Connection"); 
    if (FAILED(hr)) return FALSE; 
    try 

    hr=m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=my.mdb","","",adModeUnknown); 

    catch (_com_error &e) 

    CString errormessage; 
    errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage()); 
    AfxMessageBox(errormessage);///显示错误信息 
    return FALSE; 
    }