现有一表,内无任何记录,如何利用MFC的CRecordset或者CDatabase得到表内各个字段的名称和类型?
数据库采用access

解决方案 »

  1.   

    ODBC里面好象有函数可以枚举列的,具体是什么函数记不太清楚了,权当帮你UP了。
      

  2.   

    CODBCFieldInfo fi;
    for( int i = 0; i < GetODBCFieldCount(); i++ ) 
    GetODBCFieldInfo( i, fi );
    有关CODBCFieldInfo结构可在MSDN中有详细查到
    struct CODBCFieldInfo
    {
       CString m_strName; 
       SWORD m_nSQLType;
       UDWORD m_nPrecision;
       SWORD m_nScale;
       SWORD m_nNullability;
    };
    m_strNameThe name of the field.m_nSQLTypeThe SQL data type of the field. This can be an ODBC SQL data type or a driver-specific SQL data type. For a list of valid ODBC SQL data types, see "SQL Data Types" in Appendix D of the ODBC SDK Programmer's Reference. For information about driver-specific SQL data types, see the driver's documentation.m_nPrecisionThe maximum precision of the field. For details, see "Precision, Scale, Length, and Display Size" in Appendix D of the ODBC SDK Programmer's Reference.m_nScaleThe scale of the field. For details, see "Precision, Scale, Length, and Display Size" in Appendix D of the ODBC SDK Programmer's Reference.m_nNullabilityWhether the field accepts a Null value. This can be one of two values: SQL_NULLABLE if the field accepts Null values, or SQL_NO_NULLS if the field does not accept Null values.