Hi
I have the following problem. I would like to ReOpen a
Recordset with pRs->Open(...) using a current Connection
pCon which I used before for another Recordset.
How can I do this?
Thanx, Andrew
----- Code ------
#import "C:\Program Files\Common
Files\SYSTEM\ADO\msado15.dll" rename("EOF","AdoEof")
#include <iostream>
using namespace std;
void PrintComError(const _com_error &e)
{
// Notify the user of errors if any.
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
// Print Com errors.
printf("Error\n");
printf("\tCode = %08lx\n", e.Error());
printf("\tCode meaning = %s", e.ErrorMessage());
printf("\tSource = %s\n", (LPCSTR) bstrSource);
printf("\tDescription = %s\n", (LPCSTR)
bstrDescription);
int main(int argc, char* argv[])Quote:}
{
if( FAILED(::CoInitialize(NULL)) )
{
cout << "CoInitialize faild!" << endl;
return 1;
}
try
{
ADODB::_CommandPtr pCmd(__uuidof
(ADODB::Command));
ADODB::_ConnectionPtr pCon(__uuidof
(ADODB::Connection));
_bstr_t bstrConn = "Provider=SQLOLEDB;
Data Source=PRODSRV1; Initial Catalog=TXAC; User Id=sa;
Password=;";
_bstr_t bstrSql = "SELECT * FROM tLog";
cout << "Open ADO Connection" << endl;
pCon->Open(bstrConn, "", "",
ADODB::adConnectUnspecified);
pCmd->ActiveConnection = pCon;
pCmd->CommandType = ADODB::adCmdText;
pCmd->CommandText = bstrSql;
cout << "Open Recordset 1" << endl;
ADODB::_RecordsetPtr pRs(pCmd->Execute
(NULL, NULL, ADODB::adOpenUnspecified));
while (pRs->AdoEof != VARIANT_TRUE)
{
string strConv;
_bstr_t bstrConv;
VARIANT vLogText = pRs->Fields-
bstrConv = (_bstr_t)vLogText;Quote:>GetItem("LogText")->Value;
strConv = (string)bstrConv;
cout << strConv << endl;
pRs->MoveNext();
}
cout << "Close Recordset 1" << endl;
pRs->Close();
cout << "Open Recordset 2" << endl;
//-----------------------------------------
-------
// Problem is here!
// How can i use the Active Connection to
ReOpen a Recordset for a Query?
//-----------------------------------------
-------
// This generates ERROR!
pRs->Open("SELECT * FROM tLogAppX", pCon,
ADODB::adOpenForwardOnly, ADODB::adLockReadOnly, NULL);
// ERROR!
while (pRs->AdoEof != VARIANT_TRUE)
{
string strConv;
_bstr_t bstrConv;
VARIANT vLogText = pRs->Fields-
bstrConv = (_bstr_t)vLogText;Quote:>GetItem("LogText")->Value;
strConv = (string)bstrConv;
cout << strConv << endl;
pRs->MoveNext();
}
cout << "Close Recordset 2" << endl;
pRs->Close();
cout << "Close ADO Connection" << endl;
pCon->Close();
}
catch(const _com_error& e)
{
PrintComError(e);
}
CoUninitialize();
return 0;
Quote:}
AdoRsProblem.cpp 2K Download |