#define INITGUID
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <set>
#include <icrsint.h>//导入库文件
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")using namespace std;void dump_com_error(_com_error &e)
{
printf("Error\n");
printf("\tCode = %08lx\n", e.Error());
printf("\tCode meaning = %s", e.ErrorMessage());
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
printf("\tSource = %s\n", (LPCSTR) bstrSource);
printf("\tDescription = %s\n", (LPCSTR) bstrDescription);
}int main()
{
::CoInitialize( NULL ); //初始化环境
try{
//建立dbf连接
_ConnectionPtr pConnectionDbf(__uuidof(Connection));
_RecordsetPtr pRecordsetDbf(__uuidof(Recordset));
_CommandPtr pCommandDbf(__uuidof(Command));
_bstr_t connectionStringDbf("PROVIDER=MSDASQL; DRIVER={Microsoft Visual Foxpro Driver}; SourceDB=D:\\;SourceType=DBF");
HRESULT hrDbf = pConnectionDbf->Open( connectionStringDbf, "", "", NULL );
//_bstr_t queryStringDbf("select * from student");
_bstr_t queryStringDbf("create table mytable( id int, tname char(20) )" );
_variant_t recAffectedDbf;
pConnectionDbf->Execute( queryStringDbf,&recAffectedDbf, adCmdText );

} //end of try
catch (_com_error &e )
{
dump_com_error(e);
}
//释放资源
::CoUninitialize(); //system("pause");
return 0;
}
////////////////////////////////////////////////////////////////////////
// vc6 + sql2000 +xp
//以上程序成功的建立了一个dbf表,但是目录不是d:\,而是在c++工程的目录下
// 这个是怎么会事??
///////////////////////////////////////////////////////////////////////