473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to using ADO in the VC7 of .Net 2003

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

Nov 16 '05 #1
2 2258
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

Nov 16 '05 #2
Hi, Onega

Thanks for you suggestion. but when I create a console application on VC
2003. and compile your snippet, there are still have the error:

c:\project\console\console\Debug\msado15.tlh(2372) : error C2059: syntax
error : '-'
c:\project\console\console\Debug\msado15.tlh(2372) : error C2238: unexpected
token(s) preceding ';'
I am using the VC2003 Profession on XP Profession.What about I to do?

Thanks in advanced,

Best Regards.

Bill
"Onega" <no****@test.com> wrote in message
news:eu**************@TK2MSFTNGP12.phx.gbl...
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;
}

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ...
1
by: George | last post by:
Hi, I am trying to write a query in Oracle which I have not done before, and are having some difficulty getting my result. Please check my query and my results. select max(note.datetime),...
7
by: jennifer1970 | last post by:
I need to insert records into the table parSalesDetailModifier from OLDparSalesDetailModifier where (1) those records DO NOT exit in parSalesDetailModifier and (2) those records have a parent...
1
by: Matt Alanzo | last post by:
On another newsgroup an Access knowledgable party posted: >You should be able to connect an Access ADP to an existing SQLExpress >database running in SQLS 2000 compatibility mode. The only thing...
4
by: Max | last post by:
Hi, I would like to have a button and a combo box with options to select various versions of Microsoft Outlook: 2002, 2003. The user selects the email client and clicks the button. The only...
0
by: Jonathan Wilson | last post by:
Firstly, to get msvcrt.lib, install the .NET framework SDK. The version of msvcrt.lib included there is the exact same one as comes with Visual Studio ..NET 2003. There are some other things that...
2
by: noleander | last post by:
I'm trying to get Vis C++ std to compile using /O2 optimizing flag. Many people have suggested downloading the MS C++ 2003 Toolkit ... it supposedly has C++ compiler bins that one could use. I...
9
by: George McCullen | last post by:
I have an Outlook 2003 using Exchange Server 2003 Public Contacts Folder containing 20,000 Contacts. I am writing a VB .Net 2003 program that loops through all the contacts in a "for each oCt in...
1
by: ligong.yang | last post by:
Hi all, I got tortured by a very weird problem when I was using k. wilder's random generator class in my program. PS: wilder's generator class can be found at...
3
by: Bruce | last post by:
I have a number of Access 2000 format databases on a Windows 2003 server. For some reason I can no longer compact these databases directly on the server using Access 2003. Access 2000 seems to...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.