Mayank Jha
December 23rd, 2002, 05:54 AM
This code does not work it fails on Execute.
::CoInitialize(NULL);
_ConnectionPtr m_Connection("ADODB.Connection");
_CommandPtr m_Command("ADODB.Command");
_RecordsetPtr m_Recordset;
// Call the constructor
HRESULT hr1;
HRESULT hr2;
HRESULT hr3;
hr1 = m_Connection.CreateInstance(__uuidof(Connection));
hr2 = m_Command.CreateInstance(__uuidof(Command));
hr3 = m_Recordset.CreateInstance(__uuidof(Recordset));
if (SUCCEEDED(hr1) && SUCCEEDED(hr2))
{
m_Connection->ConnectionString = L"driver={sql server};server=RSANJAI;Database=mytemp;" L"UID=Sarmila; PWD=sarmila;";
m_Connection->CursorLocation = adUseServer;
hr3 = m_Connection->Open("", "", "", -1);
//hr3 = m_Connection->Open(L"DSN=EBPPSQL;UID=sarmila;PWD=sarmila","","",adConnectUnspecified);
//hr3 = m_Connection->Open(L"Remote Server=10.2.230.171",L"sarmila",L"sarmila",adConnectUnspecified);
if (SUCCEEDED(hr3))
{
//_variant_t vNull;
//vNull.vt = VT_NULL;
//vNull.scode = DISP_E_PARAMNOTFOUND;
m_Command->ActiveConnection = m_Connection;
m_Command->CommandType = adCmdStoredProc;
m_Command->CommandText = _bstr_t(L"sp_GetBillSummary");
m_Recordset->PutRefActiveConnection( m_Connection );
m_Recordset->PutRefSource(m_Command);
m_Command->Parameters->Refresh();
//m_Recordset->Open(vtMissing,vtMissing,adOpenKeyset,adLockBatchOptimistic,-1);
_variant_t vtRecCnt;
vtRecCnt.vt=VT_I4;
_variant_t vtEmpty (DISP_E_PARAMNOTFOUND, VT_ERROR);
_variant_t vtEmpty2 (vtEmpty);
m_Recordset = m_Command->Execute(&vtEmpty, &vtEmpty2, adCmdStoredProc);
//m_Recordset = m_Command->Execute(NULL, NULL, adCmdUnknown);
_variant_t BillID;
_variant_t biller_name;
_variant_t service_name;
_variant_t Bill_Num;
_variant_t Cust_Num_With_Biller;
_variant_t Amt_Due;
_variant_t Due_Date;
if (!m_Recordset->GetadoEOF())
{
while(!m_Recordset->GetadoEOF())
{
BillID = m_Recordset->GetCollect("Bill_ID");
biller_name = m_Recordset->GetCollect("biller_name");
service_name = m_Recordset->GetCollect("service_name");
Bill_Num = m_Recordset->GetCollect("Bill_Num");
Cust_Num_With_Biller = m_Recordset->GetCollect("Cust_Num_With_Biller");
Amt_Due = m_Recordset->GetCollect("Amt_Due");
Due_Date = m_Recordset->GetCollect("Due_Date");
m_Recordset->MoveNext();
}
}
}
}
::CoInitialize(NULL);
_ConnectionPtr m_Connection("ADODB.Connection");
_CommandPtr m_Command("ADODB.Command");
_RecordsetPtr m_Recordset;
// Call the constructor
HRESULT hr1;
HRESULT hr2;
HRESULT hr3;
hr1 = m_Connection.CreateInstance(__uuidof(Connection));
hr2 = m_Command.CreateInstance(__uuidof(Command));
hr3 = m_Recordset.CreateInstance(__uuidof(Recordset));
if (SUCCEEDED(hr1) && SUCCEEDED(hr2))
{
m_Connection->ConnectionString = L"driver={sql server};server=RSANJAI;Database=mytemp;" L"UID=Sarmila; PWD=sarmila;";
m_Connection->CursorLocation = adUseServer;
hr3 = m_Connection->Open("", "", "", -1);
//hr3 = m_Connection->Open(L"DSN=EBPPSQL;UID=sarmila;PWD=sarmila","","",adConnectUnspecified);
//hr3 = m_Connection->Open(L"Remote Server=10.2.230.171",L"sarmila",L"sarmila",adConnectUnspecified);
if (SUCCEEDED(hr3))
{
//_variant_t vNull;
//vNull.vt = VT_NULL;
//vNull.scode = DISP_E_PARAMNOTFOUND;
m_Command->ActiveConnection = m_Connection;
m_Command->CommandType = adCmdStoredProc;
m_Command->CommandText = _bstr_t(L"sp_GetBillSummary");
m_Recordset->PutRefActiveConnection( m_Connection );
m_Recordset->PutRefSource(m_Command);
m_Command->Parameters->Refresh();
//m_Recordset->Open(vtMissing,vtMissing,adOpenKeyset,adLockBatchOptimistic,-1);
_variant_t vtRecCnt;
vtRecCnt.vt=VT_I4;
_variant_t vtEmpty (DISP_E_PARAMNOTFOUND, VT_ERROR);
_variant_t vtEmpty2 (vtEmpty);
m_Recordset = m_Command->Execute(&vtEmpty, &vtEmpty2, adCmdStoredProc);
//m_Recordset = m_Command->Execute(NULL, NULL, adCmdUnknown);
_variant_t BillID;
_variant_t biller_name;
_variant_t service_name;
_variant_t Bill_Num;
_variant_t Cust_Num_With_Biller;
_variant_t Amt_Due;
_variant_t Due_Date;
if (!m_Recordset->GetadoEOF())
{
while(!m_Recordset->GetadoEOF())
{
BillID = m_Recordset->GetCollect("Bill_ID");
biller_name = m_Recordset->GetCollect("biller_name");
service_name = m_Recordset->GetCollect("service_name");
Bill_Num = m_Recordset->GetCollect("Bill_Num");
Cust_Num_With_Biller = m_Recordset->GetCollect("Cust_Num_With_Biller");
Amt_Due = m_Recordset->GetCollect("Amt_Due");
Due_Date = m_Recordset->GetCollect("Due_Date");
m_Recordset->MoveNext();
}
}
}
}