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;
}
这是一个根据表名得到字段信息,你参考一下:
#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;
}