VC6.0中操作SQL Server2000数据库 // 连接数据库 CString strConnectionString, strSql; CoInitialize(NULL); _ConnectionPtr pConn(_uuidof(Connection)); _RecordsetPtr pRst(_uuidof(Recordset)); strConnectionString = "Provider=SQLOLEDB.1;Data Source=192.168.1.1;Password=xianyue123;Persist Security Info=True;User ID=sa;Initial Catalog=MDVR"; pConn->ConnectionString = _bstr_t(strConnectionString); strSql = "select * from BaseEvents"; _bstr_t bcnstr=_bstr_t(strSql); try { pConn->Open("","","",adConnectUnspecified); pRst = pConn->Execute(bcnstr,NULL,adCmdText); m_listEvents.ResetContent(); while(!pRst->GetrsEOF()) { CString sEventName; sEventName = (char*)_bstr_t(pRst->GetCollect("EventName")); m_listEvents.AddString(sEventName); pRst->MoveNext(); } } catch(...) { } if(pRst->State) pRst->Close(); if(pConn->State) pConn->Close(); pRst.Release(); pConn.Release(); CoUninitialize();