#include <stdio.h>
#include <windows.h>
#include <string.h>
#import "c:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","adoEOF") //引入ADO库
int main(void)
{
_ConnectionPtr m_pConnection=NULL;
CoInitialize(NULL); //初始化com库
HRESULT hr = m_pConnection.CreateInstance("ADODB.Connection"); //创建Connection对象
if(SUCCEEDED(hr)) //创建数据库connection对象成功
{
hr = m_pConnection->Open("Driver={Microsoft dBase Driver (*.dbf)}","","",adModeUnknown);
if(SUCCEEDED(hr)) //连接数据库字符串成功
{
_RecordsetPtr MySet;
MySet.CreateInstance(__uuidof(Recordset));
MySet->Open("SELECT * FROM 123",m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
_variant_t Holder;
while(!MySet->adoEOF)
{
Holder = MySet->GetCollect("XMMC");
if(Holder.vt!=VT_NULL)
printf("%s\n",(char*)_bstr_t(Holder));
MySet->MoveNext();
}
}
}
return 0;
}