当前位置:首页 > 通信资讯 > 正文

本文实例讲述了VC基于ADO技术访问数据库的方法。分享给大家供大家参考。具体如下:

一、在StdAfx.h文件中添加

复制代码 代码如下: #import "C:/Program Files/Common Files/System/ado/msado15.dll" no_namespace rename("EOF","rsEOF")


导入ADO引擎。

二、数据库应用层操作

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 void CADOExample1Dlg::OnBtnQuery() { // TODO: Add your control notification handler code here CoInitialize(NULL); _ConnectionPtr pConn(__uuidof(Connection)); _RecordsetPtr pRst(__uuidof(Recordset)); pConn->ConnectionString = "Provider=SQLOLEDB.1;Password=123456;Persist Security Info=True;User ID=sa;Initial Catalog=db_test;Data Source=."; pConn->Open("","","",adConnectUnspecified); pRst = pConn->Execute("select * from tb_image",NULL,adCmdText); while(!pRst->rsEOF) { ((CListBox*)GetDlgItem(IDC_LIST1))->AddString( (_bstr_t)pRst->GetCollect("imageID")); pRst->MoveNext(); } pRst->Close(); pConn->Close(); pRst.Release(); pConn.Release(); CoUninitialize(); }

希望本文所述对大家的VC程序设计有所帮助。

如果您对该产品感兴趣,请填写办理(客服微信:xiaoxiongyidong)

为您推荐:

发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。