当vtFld = m_pRecordset->Fields->GetItem(vIndex)->Value;
  vtFld.vt == VT_NULL或者VT_EMPTY的时候
怎么知道具体那个字段是什么类型啊???
有别的方法知道吗?hellp!!!!!!!!!!!!!

解决方案 »

  1.   

    加个问题:在delphi中如何获得表的结构?
    如果此问题解决,jeffandjeff (brood) 得问题很好办啦!
      

  2.   

    OpenSchema获得表的结构, MSDN中有例子
      

  3.   

    m_pRecordset->Fields->GetItem(vIndex)->GetType();
      

  4.   

    要代码!!!
    freelove1的行不通
      

  5.   

    int nt=m_pRecordset->GetFields()->GetItem("IDF")->GetType();
    可以用阿,得到nt然后判断和msdao15.tlh中的DataTypeEnum数据对比,看看是哪一种
    enum DataTypeEnum
    {
        adEmpty = 0,
        adTinyInt = 16,
        adSmallInt = 2,
        adInteger = 3,
        adBigInt = 20,
        adUnsignedTinyInt = 17,
        adUnsignedSmallInt = 18,
        adUnsignedInt = 19,
        adUnsignedBigInt = 21,
        adSingle = 4,
        adDouble = 5,
        adCurrency = 6,
        adDecimal = 14,
        adNumeric = 131,
        adBoolean = 11,
        adError = 10,
        adUserDefined = 132,
        adVariant = 12,
        adIDispatch = 9,
        adIUnknown = 13,
        adGUID = 72,
        adDate = 7,
        adDBDate = 133,
        adDBTime = 134,
        adDBTimeStamp = 135,
        adBSTR = 8,
        adChar = 129,
        adVarChar = 200,
        adLongVarChar = 201,
        adWChar = 130,
        adVarWChar = 202,
        adLongVarWChar = 203,
        adBinary = 128,
        adVarBinary = 204,
        adLongVarBinary = 205,
        adChapter = 136,
        adFileTime = 64,
        adPropVariant = 138,
        adVarNumeric = 139,
        adArray = 8192
    };
      

  6.   

    // console.cpp : Defines the entry point for the console application.
    //#include "stdafx.h"// BeginOpenSchemaCpp
    #import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
        no_namespace rename("EOF", "EndOfFile")#include <ole2.h>
    #include <stdio.h>
    #include <oleauto.h>
    #include <conio.h>// Function declarations
    inline void TESTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);};
    void OpenSchemaX2(void);
    void PrintProviderError(_ConnectionPtr pConnection);
    void PrintComError(_com_error &e);///////////////////////////////////////////////////////////
    //                                                       //
    //      Main Function                                    //
    //                                                       //
    ///////////////////////////////////////////////////////////void main()
    {
        if(FAILED(::CoInitialize(NULL)))
            return;    OpenSchemaX2();    ::CoUninitialize();
    }///////////////////////////////////////////////////////////
    //                                                       //
    //      OpenSchemaX2 Function                            //
    //                                                       //
    ///////////////////////////////////////////////////////////
    void OpenSchemaX2() 
    {
        HRESULT  hr = S_OK;
        // Define ADO object pointers.
        // Initialize pointers on define.
        // These are in the ADODB::  namespace.
        _ConnectionPtr  pConnection2  = NULL;
        _RecordsetPtr   pRstSchema  = NULL;    _bstr_t strCnn("Provider=sqloledb;Data Source=young;"
                "Initial Catalog=pubs;User Id=sa;Password=young;");   try
        {
            // Open connection.
            TESTHR(pConnection2.CreateInstance(__uuidof(Connection)));
            pConnection2->Open (strCnn, "", "", adConnectUnspecified);        // Create a safearray which takes four elements,and pass it as 
            // 2nd parameter in OpenSchema method.
            SAFEARRAY FAR* psa = NULL;
            SAFEARRAYBOUND rgsabound;
            _variant_t  var;
            _variant_t  Array;
            rgsabound.lLbound = 0;
            rgsabound.cElements = 4;
            psa = SafeArrayCreate(VT_VARIANT, 1, &rgsabound);
            var.vt = VT_EMPTY; /*
    //TABLE_CATALOG
    //TABLE_SCHEMA
    TABLE_NAME
    //COLUMN_NAME
    */
            long ix;
            ix = 0;
            SafeArrayPutElement(psa, &ix, &var);        ix= 1;
            SafeArrayPutElement(psa, &ix, &var);        ix = 3;
            SafeArrayPutElement(psa, &ix, &var);        var.vt = VT_BSTR;
            char * s1 = "authors";
            _bstr_t str = s1;
            var.bstrVal = str;        ix = 2;
            SafeArrayPutElement(psa, &ix, &var);        Array.vt = VT_ARRAY|VT_VARIANT;
            Array.parray = psa;          pRstSchema = pConnection2->OpenSchema(adSchemaColumns,&Array);        while(!(pRstSchema->EndOfFile))
            {
                printf("COLUMN Name: %s\n", (LPCSTR) (_bstr_t) pRstSchema->
                    Fields->GetItem("COLUMN_NAME")->Value);            printf("COLUMN type: %s\n\n",(LPCSTR) (_bstr_t) pRstSchema->
                    Fields->GetItem("DATA_TYPE")->Value);            pRstSchema->MoveNext();
            }
            // Clean up objects before exit.
            pRstSchema->Close();
            pConnection2->Close(); 
        }    // End Try statement.    catch (_com_error &e)
        {
            // Notify the user of errors if any.
            // Pass a connection pointer accessed from the Connection.
            PrintProviderError(pConnection2);
            PrintComError(e);
        }
    }///////////////////////////////////////////////////////////
    //                                                       //
    //      PrintProviderError Function                      //
    //                                                       //
    ///////////////////////////////////////////////////////////void PrintProviderError(_ConnectionPtr pConnection)
    {
        // Print Provider Errors from Connection object.
        // pErr is a record object in the Connection's Error collection.
        ErrorPtr    pErr  = NULL;    if( (pConnection->Errors->Count) > 0)
        {
            long nCount = pConnection->Errors->Count;
            // Collection ranges from 0 to nCount -1.
            for(long i = 0;i < nCount;i++)
            {
                pErr = pConnection->Errors->GetItem(i);
                printf("\t Error number: %x\t%s", pErr->Number,
                    pErr->Description);
            }
        }
    }///////////////////////////////////////////////////////////
    //                                                       //
    //      PrintComError Function                           //
    //                                                       //
    ///////////////////////////////////////////////////////////void PrintComError(_com_error &e)
    {
       _bstr_t bstrSource(e.Source());
       _bstr_t bstrDescription(e.Description());    // Print COM errors. 
       printf("Error\n");
       printf("\tCode = %08lx\n", e.Error());
       printf("\tCode meaning = %s\n", e.ErrorMessage());
       printf("\tSource = %s\n", (LPCSTR) bstrSource);
       printf("\tDescription = %s\n", (LPCSTR) bstrDescription);
    }
    // EndOpenSchemaCpp