【VC开源代码栏目提醒】:网学会员鉴于大家对VC开源代码十分关注,论文会员在此为大家搜集整理了“ADOWin32DefaultStringParameter.cpp”一文,供大家参考学习
// ADOWin32DefaultStringParameter.cpp : 定义控制台应用程序的入口点。
//字符串缺省参数
#include "stdafx.h"
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
#include <stdio.h>
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
try
{
_ConnectionPtr cn("ADODB.Connection");
_RecordsetPtr rs("ADODB.Recordset");
_bstr_t strMissing(L"");
long oldPgSz = 0, newPgSz = 5;
// 使用常量strMissing和由编译器自动生成一个临时的存在于Open方法使用期间的_bstr_t
cn->Open("Provider=SQLOLEDB;SERVER=localhost;DATABASE=pubs;User Id=sa;Password=;",strMissing,"", adConnectUnspecified);
oldPgSz = rs->GetPageSize(); //或者oldPgSz = rs->PageSize;
rs->PutPageSize(newPgSz); //或者rs->PageSize = newPgSz;
//因为操作数已经是(IDispatch *)的指针,所以没有必要将//rs->PutRefActiveConnection(cn)的操作数再进行类型转换。
rs->PutRefActiveConnection( cn );
rs->Open("authors",vtMissing,adOpenStatic,adLockReadOnly,adCmdTable);
printf("Original pagesize=%d,new pagesize=%d\n",oldPgSz,rs->GetPageSize());
rs->Close();
cn->Close();
}
catch (_com_error &e)
{
printf("Description = %s\n", (char*) e.Description());
}
::CoUninitialize();
getchar();
return 0;
}