得到access的数据库表的字段的名称、类型、长度等信息

  laiyiling(最熟悉的陌生人)(知道的太少啦,好多的问题不会!) 在社区发的贴子刚找出来的 
这是一个根据表名得到字段信息,你参考一下:
#include <conio.h>
#define PAUSE printf("/npress any key to exit"); getch();

#define _WIN32_DCOM

#pragma warning(push)
#pragma warning(disable:4146)
#import "e:/program files/common files/system/ado/MSADO15.DLL" no_namespace rename("EOF", "EndOfFile")
#pragma warning(pop)

int main(int argc, char* argv[])
{
    _ConnectionPtr m_pConn;
    _RecordsetPtr m_pRs;
    CoInitializeEx(NULL, COINIT_MULTITHREADED);
    _bstr_t bstrConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;"
    "Data Source=F://lylong//db1.mdb;Persist Security Info=False";
 try{
     m_pConn.CreateInstance( __uuidof(Connection) );
     m_pRs.CreateInstance( __uuidof(Recordset) );
     m_pConn->Open( bstrConnStr, "", "", adConnectUnspecified );
     m_pRs->Open( "table1",
     m_pConn.GetInterfacePtr(), adOpenForwardOnly, adLockOptimistic, adCmdTable);

    long lColumn = m_pRs->Fields->Count;
    printf("%-12s%-10s%-10s/n", "字段名", "长度", "类型");
    for( long i=0; i<lColumn; i++ )
    {
        printf("%-12s%-10d%-10d/n", (char*)m_pRs->Fields->Item[i]->Name,
        m_pRs->Fields->Item[i]->DefinedSize,
        m_pRs->Fields->Item[i]->Type);
    }

    m_pRs->Close();
    m_pConn->Close();
 }catch( _com_error e )
 {
    printf( "/n%s Error: %ld/r/n"
        "%s/r/n"
        "%s/r/n",
        (char*)e.Source(),
        e.Error(),
        (char*)e.Description(),
        (char*)e.ErrorMessage() );
    m_pRs->Close();
    m_pConn->Close();
}
CoUninitialize();
PAUSE;
return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值