#include "stdafx.h"
#include <stdio.h>
#include <Windows.h>
#include <WinDef.h>
#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","adoEOF") rename("BOF","adoBOF")
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(0);
_ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
try{
m_pConnection.CreateInstance("ADODB.Connection");
_bstr_t strConnect="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\db1.mdb;Persist Security Info=False";
m_pConnection->Open(strConnect,"","",adModeUnknown);
m_pRecordset.CreateInstance(__uuidof(Recordset));
_bstr_t bstrSQL="select * from table01";
m_pRecordset->Open(bstrSQL,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
_variant_t vNo,vEmployee,vAge;
while(!m_pRecordset->adoEOF){
vNo =m_pRecordset->GetCollect((long)0);
vEmployee=m_pRecordset->GetCollect("employee");
vAge =m_pRecordset->GetCollect("age");
printf("%d,%s,%d\n",vNo.lVal,(LPCTSTR)(_bstr_t)vEmployee,vAge.lVal);
}
bstrSQL="insert into table01 values(18,'jkk',30)";
m_pConnection->Execute(bstrSQL,NULL,adCmdText);
m_pConnection->CommitTrans();
m_pRecordset->Close();
if(m_pConnection->State)m_pConnection->Close();
}catch(_com_error e){
printf("com error!\n");
}
CoUninitialize();
return 0;
}
|