
ADO Problem with calling a stored procedure in MS Access 2000
I am using sample Northwind.MDB that came with Office 2000. The code
snippet below connects and runs successfully if the stored procedure
is one word (such as "Invoices" below).
However, when I try to run another stored procedure that contains more
than one word, such as "Current Product List", an exception is thrown.
I've tried "CurrentProductList" and the same problem.
What _bstr_t do I use to run a stored procedure that is more than one
word? Thanks for your help.
=====================================================================
Error:80040e14.
ErrorMessage:IDispatch error #3092.
Source:Microsoft JET Database Engine.
Description:Invalid SQL statement; expected 'DELETE', 'INSERT',
'PROCEDURE', 'SELECT', or 'UPDATE'..
First-chance exception in ADO.exe (KERNEL32.DLL): 0xE06D7363:
Microsoft C++ Exception.
=====================================================================
_CommandPtr pCommand;
pCommand.CreateInstance( __uuidof( Command ) );
CADODoc * pDoc = GetDocument();
try
{
pCommand->ActiveConnection = pDoc->m_pConnection;
pCommand->CommandType = adCmdStoredProc;
pCommand->CommandText = _bstr_t( "Invoices" );
_variant_t vNull;
vNull.vt = VT_ERROR;
vNull.scode = DISP_E_PARAMNOTFOUND;
_RecordsetPtr pRS = pCommand->Execute( &vNull, &vNull, adCmdUnknown );
if( !pRS->GetadoEOF() )
{
CListCtrlEx& ctlList = (CListCtrlEx&) GetListCtrl();
ctlList.DeleteAllItems();
while(ctlList.DeleteColumn(0));
ctlList.AddColumn(" ProductID ",0);
ctlList.AddColumn(" ProductName ",1);
ctlList.AddColumn(" Counter ",2);
_variant_t vProductID, vProductName;
int i = 0;
while( !pRS->GetadoEOF() )
{
vProductID = pRS->GetCollect(L"ProductID");
ctlList.AddItem(i,0,(_bstr_t) vProductID);
vProductName = pRS->GetCollect(L"ProductName");
ctlList.AddItem(i,1,(_bstr_t) vProductName);
m_strConvert.Format("%d", i);
ctlList.AddItem(i, 0, (LPCTSTR) m_strConvert);
pRS->MoveNext();
}
}
TRACE("\nEOF reached. Closing Database Connection! \n");
pRS->Close();
Quote:
}
catch( _com_error &ex )
{
TRACE( "Error:%08lx.\n", ex.Error() );
TRACE( "ErrorMessage:%s.\n", ex.ErrorMessage() );
TRACE( "Source:%s.\n", (LPCTSTR) _bstr_t(ex.Source())
TRACE( "Description:%s.\n", (LPCTSTR) _bstr_t(ex.Description()) );
Quote:
}