如果,你是用VC++的话,可以使用ADO。
例子如下:
// ADOSample.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <objbase.h>
#include <oledb.h>
#include <atlbase.h>
#include <windows.h>
#include <comdef.h>#import "c:\\Program Files\\Common Files\\System\\ADO\\msado15.dll" no_namespace rename("EOF", "EndOfFile")
#import "C:\Program Files\Microsoft SQL Server\80\Tools\Binn\sqldmo.dll" void dump_com_error(_com_error &e)
{
printf("Error\n");
printf("\a\tCode = %08lx\n", e.Error());
printf("\a\tCode meaning = %s", e.ErrorMessage());
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
printf("\a\tSource = %s\n", (LPCSTR) bstrSource);
printf("\a\tDescription = %s\n", (LPCSTR) bstrDescription);
}
int main(int argc, char* argv[])
{
printf("Hello World!\n");
::CoInitialize(NULL);
try
{ _ConnectionPtr pCon=NULL;
_RecordsetPtr pRs=NULL;
pCon.CreateInstance(__uuidof(Connection));
pCon->Open("Export","dongsong","dongsong",adConnectUnspecified);
pRs.CreateInstance(__uuidof(Recordset));
pRs->CursorLocation=adUseClient;
pRs->Open("select name from sysobjects where type='u'",
_variant_t((IDispatch *) pCon, true),adOpenStatic, adLockReadOnly, adCmdUnknown);
while (!(pRs->EndOfFile))
{
printf("%s\n",(char*)_bstr_t(pRs->Fields->Item["name"]->Value));
pRs->MoveNext();
}
}catch (_com_error &e)
{
dump_com_error(e);
}
::CoUninitialize();
return 0;
}
例子如下:
// ADOSample.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <objbase.h>
#include <oledb.h>
#include <atlbase.h>
#include <windows.h>
#include <comdef.h>#import "c:\\Program Files\\Common Files\\System\\ADO\\msado15.dll" no_namespace rename("EOF", "EndOfFile")
#import "C:\Program Files\Microsoft SQL Server\80\Tools\Binn\sqldmo.dll" void dump_com_error(_com_error &e)
{
printf("Error\n");
printf("\a\tCode = %08lx\n", e.Error());
printf("\a\tCode meaning = %s", e.ErrorMessage());
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
printf("\a\tSource = %s\n", (LPCSTR) bstrSource);
printf("\a\tDescription = %s\n", (LPCSTR) bstrDescription);
}
int main(int argc, char* argv[])
{
printf("Hello World!\n");
::CoInitialize(NULL);
try
{ _ConnectionPtr pCon=NULL;
_RecordsetPtr pRs=NULL;
pCon.CreateInstance(__uuidof(Connection));
pCon->Open("Export","dongsong","dongsong",adConnectUnspecified);
pRs.CreateInstance(__uuidof(Recordset));
pRs->CursorLocation=adUseClient;
pRs->Open("select name from sysobjects where type='u'",
_variant_t((IDispatch *) pCon, true),adOpenStatic, adLockReadOnly, adCmdUnknown);
while (!(pRs->EndOfFile))
{
printf("%s\n",(char*)_bstr_t(pRs->Fields->Item["name"]->Value));
pRs->MoveNext();
}
}catch (_com_error &e)
{
dump_com_error(e);
}
::CoUninitialize();
return 0;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货