如何在vc中打开数据库后用嵌入式的sql查询

asdasdasd 2003-03-25 02:14:46
打开.dbf后,怎么实现表的spl查询,选择等
或者能不能打开整个数据库,用嵌入式的spl查询
...全文
34 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
tanaier 2003-03-25
  • 打赏
  • 举报
回复
file->new win32 console project.empty project.add vfp.cpp
#include <windows.h>
#include <stdio.h>
#import "c:\Program Files\Common Files\System\ADO\msado20.tlb" \
no_namespace rename("EOF", "EndOfFile")
void PrintProviderError(_ConnectionPtr pConnection)
{
ErrorPtr pErr = NULL;
if( (pConnection->Errors->Count) > 0)
{
long nCount = pConnection->Errors->Count;
for(long i = 0;i < nCount;i++)
{
pErr = pConnection->Errors->GetItem(i);
printf("\t Error number: %x\t%s", pErr->Number,pErr->Description);
}
}
}
void main()
{
if(FAILED(::CoInitialize(NULL)))
return ;
_ConnectionPtr pConnection = NULL;
_bstr_t strConnection = TEXT("Driver={Microsoft dBASE Driver (*.dbf)};DBQ=C:\\; DriverID=533;");
try
{

_RecordsetPtr pRstSchema = NULL;
_CommandPtr pCommand=NULL;
pConnection.CreateInstance(__uuidof(Connection));
pConnection->Open (strConnection, "", "", -1);
pCommand.CreateInstance (__uuidof(Command));
pRstSchema.CreateInstance (__uuidof(Recordset));
_bstr_t sqltext="select * from jck98 ";
pCommand->ActiveConnection =pConnection;
pCommand->CommandText =sqltext;
pCommand->CommandType=adCmdText;

pRstSchema = pCommand->Execute (NULL,NULL,adCmdText);
_variant_t filed[17];
_bstr_t filedname[17];
while (!pRstSchema->EndOfFile )
{
long kk=pRstSchema->GetFields ()->GetCount ();
for (long uu=0;uu<kk;uu++)
{
filedname[uu]=pRstSchema->GetFields ()->GetItem ((_variant_t)uu)->GetName ();
filed[uu]=pRstSchema->GetCollect (filedname[uu]);
}
pRstSchema->MoveNext ();
}
pRstSchema->Close();
pConnection->Close();
}
catch(...)
{
PrintProviderError(pConnection);
}
::CoUninitialize();
}

4,017

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧