|
// xmlrsobj.cpp : Implementation of Cxmlrsobj
#include "stdafx.h"
#include "Xmlrs.h"
#include "xmlrsobj.h"
#import "C:\Program Files\Common Files\System\ADO\msado15.dll" \
named_guids no_namespace rename("EOF", "EndOfFile")
inline void TESTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);};
bool GetRowsOK(_RecordsetPtr pRstTemp,int intNumber,
_variant_t& avarData);
/////////////////////////////////////////////////////////////////////////////
// Cxmlrsobj
// global variable save the recordset point of Employees table
_RecordsetPtr pRstEmployees = NULL;
STDMETHODIMP Cxmlrsobj::ConnectDB(BSTR bstrConn)
{
// Get the Innstance of Recordset
TESTHR(pRstEmployees.CreateInstance(__uuidof(Recordset)));
// Open the recordset by the specific SELECT
pRstEmployees->Open("SELECT fName, lName, hire_date "
"FROM Employee ORDER BY lName",
bstrConn, // Connection string comes from the ASP client
adOpenStatic, adLockReadOnly, adCmdText);
return S_OK;
}
STDMETHODIMP Cxmlrsobj::GetXmlrs(BSTR *bstrXmlrs)
{
_bstr_t bstrTmp;
// Wrap the Recordset into an XML format
bstrTmp = "<Recordset>";
while (true)
{
bstrTmp += "<Record>";
bstrTmp += "<fName>";
bstrTmp += (_bstr_t)pRstEmployees->Fields->Item["fName"]->Value;
bstrTmp += "</fName><lName>";
bstrTmp += (_bstr_t)pRstEmployees->Fields->Item["lName"]->Value;
bstrTmp += "</lName><hire_date>";
bstrTmp += (_bstr_t)pRstEmployees->Fields->Item["hire_date"]->Value;
bstrTmp += "</hire_date>";
bstrTmp += "</Record>";
pRstEmployees->MoveNext();
if (pRstEmployees->EndOfFile)
{
break;
}
}
bstrTmp += "</Recordset>";
*bstrXmlrs = bstrTmp.copy();
return S_OK;
}
STDMETHODIMP Cxmlrsobj::CloseDB()
{
// Close the database
pRstEmployees->Close();
return S_OK;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.