This article describes the VC based on ADO technology access to the database method. Share to everyone for your reference. Specifically as follows:
First, add in the StdAfx.h file
Copy Code code as follows:
#import "C:/Program Files/common files/system/ado/msado15.dll" no_namespace rename ("EOF", "rseof")
Import the ADO engine.
Second, the database application layer operation
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 ();
}
I hope this article on the VC program for everyone to help.