设为首页 加入收藏

TOP

VC6ADO连接SQL2005
2014-11-23 21:30:12 】 浏览:482
Tags:VC6ADO 连接 SQL2005
By 闲鸟归来 , Posted in 死亡笔记
01 /*dbo.bank 数据库内有customername、currentmoney两列*/
02
03 /*在对应头文件+入一句:*/
04 #import "c:Program FilesCommon FilesSystemadomsado15.dll" no_namespace rename("EOF", "adoEOF")
05
06 /*如下为具体ADO连接与查询语句执行*/
07 CoInitialize(NULL); // 初始化COM环境
08 _ConnectionPtr cnn(__uuidof(Connection)); // 建立Connection
09 _RecordsetPtr rst(__uuidof(Recordset));
10 _CommandPtr cmd(__uuidof(Command));
11 cnn->ConnectionString = (_bstr_t)loginConnStr;
12 // CString loginConnStr = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=bank;Data Source=PCADMIN\SQL2005"; // 数据源
13 cnn->Open("", "", "", adConnectUnspecified); // 数据源已经准备好,前3参数为空
14 cmd->put_ActiveConnection(_variant_t((IDispatch*)cnn));
15 cmd->CommandText = "select * from bank";
16 rst = cmd->Execute(NULL, NULL, adCmdText);
17 while ( !rst->adoEOF )
18 {
19 ::AfxMessageBox((_bstr_t)rst->GetCollect("customername")); // 直接MsgBox出来~
20 rst->MoveNext();
21 }
22 rst->Close(); // 关闭
23 cnn->Close();
24 rst.Release(); // 释放
25 cnn.Release();
26 CoUninitialize();
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇教你透彻了解红黑树 下一篇VC.NET不带纯真数据库版的显IP物..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目