ADO数据库示例

来源:互联网 发布:获取网站点击数据 编辑:程序博客网 时间:2024/05/16 06:00
// stdafx.h#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "NUL")// adodlg.cppCoInitialize(NULL);_ConnectionPtr spConn(__uuidof(Connection));_RecordsetPtr spSet(__uuidof(Recordset));_CommandPtr spCmd(__uuidof(Command)); // (3) GoodspConn->ConnectionString = "Provider=SQLOLEDB.1;Data Source=(local);Initial Catalog=pubs;Integrated Security=SSPI;";spConn->Open("", "", "", adConnectUnspecified); // spSet = spConn->Execute("SELECT * FROM authors", NULL, adCmdText); (1)// spSet->Open("SELECT * FROM authors", _variant_t((IDispatch*) spConn), adOpenDynamic, adLockOptimistic, adCmdText); (2)spCmd->put_ActiveConnection(_variant_t((IDispatch*) spConn)); // (3)spCmd->CommandText = "SELECT * FROM authors"; // (3)spSet = spCmd->Execute(NULL, NULL, adCmdText); // (3);while (!spSet->NUL){  ((CListBox*) GetDlgItem(IDC_LIST1))->AddString(   (_bstr_t) spSet->GetCollect("au_lname"));  spSet->MoveNext();}spSet->Close();spConn->Close();CoUninitialize();