The following code snippet works in VC2003, hope it helps.
Best Regards
Onega
#include "stdafx.h"
#import "c:\Program Files\Common Files\System\ado\msado15.dll" no_namespace
rename("EOF", "EndOfFile")
VOID PrintProviderError(_ConnectionPtr pConnection)
{
// Print Provider Errors from Connection object.
// pErr is a record object in the Connection's Error collection.
ErrorPtr pErr = NULL;
long nCount = 0;
long i = 0;
if( (pConnection->Errors->Count) > 0)
{
nCount = pConnection->Errors->Count;
// Collection ranges from 0 to nCount -1.
for(i = 0; i < nCount; i++)
{
pErr = pConnection->Errors->GetItem(i);
printf("\n\t Error number: %x\t%s", pErr->Number,
(LPCSTR)pErr->Description);
}
}
}
/*
CREATE PROCEDURE "ONEGA"."TestProc1"
(
p_out OUT numeric,
p_id IN numeric DEFAULT 1
)
IS
BEGIN
p_out:= p_id + 1234;
return;
END
;
*/
int main(int argc, char* argv[])
{
printf("Use ADO to open Oracle!\n");
CoInitialize(NULL);
_ConnectionPtr pConn("ADODB.Connection");
try
{
_CommandPtr Cmd1;
Cmd1.CreateInstance( __uuidof( Command ) );
_ParameterPtr outParam=NULL;
_RecordsetPtr pRst("ADODB.Recordset");
pConn->Open("Provider=OraOLEDB.Oracle;Data Source=workdb;User
Id=Onega;Password=sa;"
,"","",adConnectUnspecified);
Cmd1->ActiveConnection = pConn;
Cmd1->CommandText = "{call ONEGA.TestProc1( ?)}";
Cmd1->CommandType = adCmdText;
outParam =
Cmd1->CreateParameter("p_out",adInteger,adParamOutput,s izeof(int));
Cmd1->Parameters->Append(outParam);
Cmd1->Execute(NULL,NULL,adExecuteNoRecords);
long p2=Cmd1->Parameters->Item["p_out"]->Value;
printf("p2= %d,\n",p2);
pConn->Close();
}
catch(_com_error &e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
printf("\nCOM error occurred, Source : %s \n Description : %s
\n",(LPCSTR)bstrSource,(LPCSTR)bstrDescription);
PrintProviderError(pConn);
}
::CoUninitialize();
printf("program end.\n");
return 0;
}
"Bill Sun" <su******@hotpop.com> wrote in message
news:#L**************@TK2MSFTNGP11.phx.gbl...
Hi,
I want to compile the MS's program: ADOXCreateDatabaseX.cpp on
VC7 of .Net 2003. The compiler always told me:
c:\project\console\console\Debug\msado15.tlh(2374) : error C2059: syntax
error : '-'
c:\project\console\console\Debug\msado15.tlh(2374) : error C2238:
unexpected token(s) preceding ';'
If I compile these with VC6, then no problem.
Who can tell me how to make the compiling pass.
By the way, I want develop ADO application on the VC6 and VC7 at same
time. so,
how to make the two sources code to keeping consistent on the same time.
that is means I want develop the program on VC7 of .net can also be
compile on VC6.0.
Thanks advanced,
Bill