把SQL2000的里的表导出为foxpro的dbf的问题
问题一:用什么方式实现?
因为没有找到好的方式,我打算采用用ADO的方式来实现,思路如下:
1.连接SQL;
2.读出字段信息;
3.根据2的信息,使用SQL语句建立一个空的dbf文件;
4.把SQL里的记录读到dbf中去。
问题二:第3步怎么做?
//===========以下已经实现到第2步==========
#define INITGUID
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <set>
#include <icrsint.h>
//#include "dbf.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{
//建立sql连接
_ConnectionPtr pConnectionSQL("ADODB.Connection");
_RecordsetPtr pRecordsetSQL("ADODB.Recordset");
_CommandPtr pCommandSQL("ADODB.Command");
_bstr_t connectionStringSQL("Driver={SQL Server}; Server=(local); Uid=sa; Pwd=; Database=pubs");
pConnectionSQL->ConnectionTimeout=3; //设置超时时间为3秒
pConnectionSQL->Open(connectionStringSQL,"","",NULL);
//执行命令
_bstr_t queryStringSQL("select * from authors");
_variant_t recAffectedSQL; //受影响的记录行数
pRecordsetSQL->Open(queryStringSQL, _variant_t((IDispatch *)pConnectionSQL,true), adOpenKeyset,adLockBatchOptimistic, adCmdText);
//第2步:读出字段名
long limit = pRecordsetSQL->GetFields()->Count;
for (long x = 0; x < limit; x++)
cout << (char*) pRecordsetSQL->GetFields()->Item[x]->Name << endl;
//第3步:根据2的信息,建立dbf数据表
//?????????????????????????????????????
//关闭记录集、关闭连接
if(pRecordsetSQL->State) pRecordsetSQL->Close();
if(pConnectionSQL->State) pConnectionSQL->Close();
} //end of try
catch (_com_error &e )
{
dump_com_error(e);
}
//释放资源
::CoUninitialize();
//system("pause");
return 0;
}