- UID
- 44710
- 积分
- 13
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2003-4-23
- 最后登录
- 1970-1-1
|
发表于 2003-4-26 19:29:12
|
显示全部楼层
.h
#ifndef _ADOVISIT_H
#define _ADOVISIT_H
#define INITGUID
#import "C:\Program Files\Common Files\SYSTEM\ADO\msado15.dll"\
no_namespace rename("EOF", "EndOfFile"),\
no_namespace rename("LockTypeEnum", "LockTypeEnumA"),\
no_namespace rename("DataTypeEnum", "DataTypeEnumA"),\
no_namespace rename("FieldAttributeEnum", "FieldAttributeEnumA"),\
no_namespace rename("EditModeEnum", "EditModeEnumA"),\
no_namespace rename("RecordStatusEnum", "RecordStatusEnumA"),\
no_namespace rename("ParameterDirectionEnum", "ParameterDirectionEnumA"),\
no_namespace rename("EOS", "EOSA")
#include "comdef.h"
#include "stdio.h"
#include "adoid.h"
#include "icrsint.h"
#include "acutads.h"
class CCustomRs : public CADORecordBinding
{
BEGIN_ADO_BINDING(CCustomRs)
ADO_VARIABLE_LENGTH_ENTRY2(1, adVarChar, m_code,
sizeof(m_code), codeStatus, FALSE)
ADO_VARIABLE_LENGTH_ENTRY2(2, adVarChar, m_count,
sizeof(m_count), countStatus, FALSE)
ADO_VARIABLE_LENGTH_ENTRY2(3, adVarChar, m_direction,
sizeof(m_direction), directionStatus, FALSE)
END_ADO_BINDING()
public:
CHAR m_code[41];
ULONG codeStatus;
CHAR m_count[12];
ULONG countStatus;
CHAR m_direction[41];
ULONG directionStatus;
};
void VisitMdb();
#endif
.cpp
#include "StdAfx.h"
#include "AdoVisit.h"
#include "conio.h"
#include "ole2.h"
void dump_com_error(_com_error &e)
{
acutPrintf("Error\n");
acutPrintf("\a\tCode = %08lx\n", e.Error());
acutPrintf("\a\tCode meaning = %s", e.ErrorMessage());
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
acutPrintf("\a\tSource = %s\n", (LPCSTR) bstrSource);
acutPrintf("\a\tDescription = %s\n", (LPCSTR) bstrDescription);
}
void
VisitMdb()
{
HRESULT hr;
IADORecordBinding *picRs = NULL;
_ConnectionPtr pConn("ADODB.Connection");
_RecordsetPtr pRs("ADODB.Recordset");
CCustomRs rs;
::CoInitialize(NULL);
try
{
pConn->Open("Provider=Microsoft.Jet.OLEDB.4.0;\
Data Source=e:\\kable\\basefiles\\Weld.mdb",\
"","",adModeUnknown);
pRs->Open("select * from WeldingCode", (IDispatch*)pConn,
adOpenDynamic, adLockOptimistic, adCmdUnknown);
if (FAILED(hr = pRs->QueryInterface(__uuidof(IADORecordBinding),
(LPVOID*)&picRs)))
_com_issue_error(hr);
if (FAILED(hr = picRs->BindToRecordset(&rs)))
_com_issue_error(hr);
pRs->MoveFirst();
while (!pRs->EndOfFile)
{
acutPrintf("\a\tcode: %s\t count:%s\tdirection: %s\n",
(rs.codeStatus == adFldOK ? rs.m_code : ""),
(rs.countStatus == adFldOK ? rs.m_count: ""),
(rs.directionStatus == adFldOK ? rs.m_direction: ""));
pRs->MoveNext();
}
pConn->BeginTrans();
pRs->UpdateBatch(adAffectAll);
pConn->CommitTrans();
}
catch (_com_error &e)
{
dump_com_error(e);
}
if (picRs)
picRs->Release();
CoUninitialize();
}
1.有的#include文件要用尖括号,奇怪用尖括号贴不上去
2.这个程序可以运行,我总觉得有点怪怪的,请高手赐教 |
|