473,398 Members | 2,120 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,398 software developers and data experts.

Passing parameters to Oracle stored procedure?

I'm trying to call a parameterized stored procedure in C# using
microsoft ODBC .NET. Could you please give me some help or hint? Thank
you very much!

C# code:
.... //connection code
odbcCommand.CommandType = CommandType.StoredProcedure;
odbcCommand.CommandText = "BEGIN myProc(?, ?); END;";
odbcCommand.CommandTimeout = 0;

OdbcParameter paramA =
odbcCommand.Parameters.Add("@A_CNT", OdbcType.Int);
paramA.Value = _a_cnt;
OdbcParameter paramB =
odbcCommand.Parameters.Add("@B_CNT", OdbcType.Int);
paramB.Value = _b_cnt;

try
{
odbcCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.Error.WriteLine(DateTime.Now.ToString()
+ ex.Message);
throw ex;
}

The SP itself looks like:
CREATE OR REPLACE PROCEDURE myProc (
A_CNT IN BINARY_INTEGER,
B_CNT IN BINARY_INTEGER) AS
BEGIN
NULL;
COMMIT;
END;

I tried to directly use
odbcCommand.CommandText = "BEGIN myProc(1, 2); END;";
And that works! However, unfortunately I actually need to use the two
variables _a_cnt and _b_cnt as input arguments for the SP. Then I got
following error message which complains about the question mark in
"BEGIN myProc(?, ?); END;"

ERROR [HY000]
[Oracle][ODBC][Ora]ORA-06550: line 1, column 14:PLS-00103: Encountered
the symbol
"" when expecting one of the following: ( ) - + case mod new not null
others
<an identifier>
<a double-quoted delimited-identifier<a bind variable>
table avg count current exists max min prior sql stddev sum
variance execute multiset the both leading trailing forall
merge year month DAY_ hour minute second timezone_hour
timezone_minute timezone_region timezone_abbr time timestamp
interval date
<a

The suspicious symbol in the error message is a question mark upside
down.

Oracle 10g release 2.

Jul 17 '06 #1
3 10908

<ta***********@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
I'm trying to call a parameterized stored procedure in C# using
microsoft ODBC .NET. Could you please give me some help or hint? Thank
you very much!

C# code:
... //connection code
odbcCommand.CommandType = CommandType.StoredProcedure;
odbcCommand.CommandText = "BEGIN myProc(?, ?); END;";
odbcCommand.CommandTimeout = 0;
. . .
First, the CommandType is wrong. It should be CommandType.Text. You have
supplied a complete PL/SQL block which happens to invoke a stored procedure.
CommandType.StoredProcedure is used when you specify only the procedure
name, and let the driver build the PL/SQL block for you.

Second, why are you using ODBC instead of System.Data.OracleClient?

Third, the PL/SQL you have supplied is invalid. Parameter markers must be
preceded by a ':' in Oracle.

odbcCommand.CommandText = "BEGIN myProc(:A_CNT, :B_CNT); END;";

David
Jul 17 '06 #2
Hi David,
Thanks for your quick reply. It's using Odbc rather than
OracleClient because this code is unified code for both SQL Server and
Oracle.
I modified the commandType to be CommandType.Text and use "BEGIN
myProc(:A_CNT, :B_CNT); END;" as the CommandText, but still got exact
same error message. It looks like that it's complaining the symbol ":"
this time but the symbol shown in the error message is still upside
down question mark.

Tao

David Browne wrote:
<ta***********@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
I'm trying to call a parameterized stored procedure in C# using
microsoft ODBC .NET. Could you please give me some help or hint? Thank
you very much!

C# code:
... //connection code
odbcCommand.CommandType = CommandType.StoredProcedure;
odbcCommand.CommandText = "BEGIN myProc(?, ?); END;";
odbcCommand.CommandTimeout = 0;
. . .

First, the CommandType is wrong. It should be CommandType.Text. You have
supplied a complete PL/SQL block which happens to invoke a stored procedure.
CommandType.StoredProcedure is used when you specify only the procedure
name, and let the driver build the PL/SQL block for you.

Second, why are you using ODBC instead of System.Data.OracleClient?

Third, the PL/SQL you have supplied is invalid. Parameter markers must be
preceded by a ':' in Oracle.

odbcCommand.CommandText = "BEGIN myProc(:A_CNT, :B_CNT); END;";

David
Jul 17 '06 #3

<ta***********@gmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
Hi David,
Thanks for your quick reply. It's using Odbc rather than
OracleClient because this code is unified code for both SQL Server and
Oracle.
OK, but it's generally better to use the .NET generic providers or
Enterprise Library for this.

Generic Coding with the ADO.NET 2.0 Base Classes and Factories
http://msdn.microsoft.com/library/de...vsgenerics.asp

Data Access Application Block
http://msdn.microsoft.com/library/de...ssappblock.asp
I modified the commandType to be CommandType.Text and use "BEGIN
myProc(:A_CNT, :B_CNT); END;" as the CommandText, but still got exact
same error message. It looks like that it's complaining the symbol ":"
this time but the symbol shown in the error message is still upside
down question mark.
I never use ODBC, so I'm not sure what's really happening there.
David
Jul 17 '06 #4

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

Similar topics

0
by: Aaron | last post by:
The following code works fine when previewing a Crystal report using ASP, EXCEPT when it gets to a report using a SubReport and its associated parameters. The whole report just comes up blank with...
3
by: WGW | last post by:
Though I am a novice to MS SQL server (2000 I believe), I can do almost! everything I need. Maybe not efficiently, but usefully. However, I have a problem -- a complex query problem... I can...
2
by: zlatko | last post by:
There is a form in an Access Project (.adp, Access front end with SQL Server) for entering data into a table for temporary storing. Then, by clicking a botton, several action stored procedures...
2
by: Bob | last post by:
I'm new to Access projects and SQL server and am not a veteran VB programmer. There's a cry for help! I'm attempting to print the current form on screen by using a command button which the user...
4
by: Mike Dinnis | last post by:
Hi, I've been working through a number of turorials to try to learn more about retrieving data from a SQL database. I think i've mastered techniques where i create a sql string in the page and...
4
by: Magy | last post by:
What would be the best way to execute a Oracle stored procedure that excepts several input paramters, through a web method in vb.net. What would be a good way to get to the web method, the Oracle...
4
by: Ranginald | last post by:
Hi, I'm having trouble passing a parameter from my default.aspx page to my default2.aspx page. I have values from a query in a list box and the goal is to pass the "catID" from default.aspx...
14
by: jehugaleahsa | last post by:
Hello: I am working with Oracle .NET Stored Procedures. I would like to know how to return the results of a SELECT statement. I have tried returning a OracleRefCursor and a DataTable, but...
1
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
Can anyone offer pointers to articles/examples of passing a Ref Cursor ***IN*** to an Oracle stored procedure. I find tons of examples for getting a ref cursor OUT of a stored procedure. I'm using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.