print?#include <string>
//c:\Program Files\Common Files\System\ADO\msado15.dll
#import "msado15.dll" no_namespace rename("EOF", "EndOfFile")
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
::CoInitialize(NULL);
_ConnectionPtr m_pConnection=NULL;
_RecordsetPtr m_pRecordset=NULL;
m_pConnection.CreateInstance(__uuidof(Connection));
m_pRecordset.CreateInstance(__uuidof(Recordset));
_bstr_t strConnect = "Provider=SQLOLEDB.1;Password=123456;Persist Security Info=True;\
User ID=sa;Initial Catalog=testdb;Data Source=192.168.1.3";
_bstr_t bstrSQL("select * from testTable");
try
{
m_pConnection->Open(strConnect, "","", adModeUnknown);
m_pRecordset->Open(bstrSQL, m_pConnection.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText);
_variant_t vstr, vuint;
while (!m_pRecordset->EndOfFile)
{
vstr = m_pRecordset->GetCollect("str");
vuint = m_pRecordset->GetCollect("uint");
string str = (_bstr_t)vstr.bstrVal;
unsigned int uint = vuint.ulVal;
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
}
catch (_com_error e)
{
return 0;
}
if(m_pConnection->State)
{
m_pConnection->Close();
}
::CoUninitialize();
return 0;
}