weiren2006 通过本文主要向大家介绍了vc ado连接数据库,vc ado数据库编程,vc ado,vc ado excel,vc ado access等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
本文实例讲述了VC基于ADO技术访问数据库的方法。分享给大家供大家参考。具体如下:
一、在StdAfx.h文件中添加
导入ADO引擎。
二、数据库应用层操作
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(); }</div>
希望本文所述对大家的VC程序设计有所帮助。
</div>