473,387 Members | 1,464 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,387 software developers and data experts.

OracleParameter for Dynamic SQL doesn't get set

I get this error when trying to use a paramter on a dynamic sql statement.
What am I doing wrong.

Exception Details: System.Data.OracleClient.OracleException: ORA-01036:
illegal variable name/number

Here is the code:

Dim strSQL As String
Dim intMyVal as integar = 5
strSQL = "SELECT * FROM TABLE WHERE(NUMBERCOL = @VAL)"

Dim oOracleConn As New OracleConnection(connstring)
If oOracleConn.State = ConnectionState.Closed Then
oOracleConn.Open()
End If

Dim cmdRoles As New OracleCommand(strSQL, oOracleConn)
cmdRoles.CommandType = CommandType.Text

Dim prm1 As New OracleParameter("@VAL", OracleType.Number)
prm1.Size = 3
prm1.Scale = 0
prm1.Value = intMyVal
prm1.Direction = ParameterDirection.Input
prm1.SourceVersion = DataRowVersion.Current
cmdRoles.Parameters.Add(prm1)

Dim dsNames As New DataSet
Dim da As New OracleDataAdapter(cmdRoles)
da.Fill(dsRoles) <-- fails here. when executing the command.

I do not how to make this work. The oracle column is NUMBER SIZE 3, SCALE 0.
Any help would be appreciated.
--
Mike Logan
Nov 18 '05 #1
4 3419
The Oracle Data Provider works a little bit differently than the SQL Server
data provider.

Your parameter name should begin with a : instead of an @
Then when you add the parameter, don't use the : in front of it for the
parameter name.

So your code would look like:
Dim strSQL As String
Dim intMyVal as integar = 5
strSQL = "SELECT * FROM TABLE WHERE(NUMBERCOL = :VAL)"

Dim oOracleConn As New OracleConnection(connstring)
If oOracleConn.State = ConnectionState.Closed Then
oOracleConn.Open()
End If

Dim cmdRoles As New OracleCommand(strSQL, oOracleConn)
cmdRoles.CommandType = CommandType.Text

Dim prm1 As New OracleParameter("VAL", OracleType.Number)
prm1.Size = 3
prm1.Scale = 0
prm1.Value = intMyVal
prm1.Direction = ParameterDirection.Input
prm1.SourceVersion = DataRowVersion.Current
cmdRoles.Parameters.Add(prm1)

Dim dsNames As New DataSet
Dim da As New OracleDataAdapter(cmdRoles)
da.Fill(dsRoles) <-- fails here. when executing the command.
--
Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com
"Mike" <Mi*******@community.nospam> wrote in message
news:FC**********************************@microsof t.com...I get this error when trying to use a paramter on a dynamic sql statement.
What am I doing wrong.

Exception Details: System.Data.OracleClient.OracleException: ORA-01036:
illegal variable name/number

Here is the code:

Dim strSQL As String
Dim intMyVal as integar = 5
strSQL = "SELECT * FROM TABLE WHERE(NUMBERCOL = @VAL)"

Dim oOracleConn As New OracleConnection(connstring)
If oOracleConn.State = ConnectionState.Closed Then
oOracleConn.Open()
End If

Dim cmdRoles As New OracleCommand(strSQL, oOracleConn)
cmdRoles.CommandType = CommandType.Text

Dim prm1 As New OracleParameter("@VAL", OracleType.Number)
prm1.Size = 3
prm1.Scale = 0
prm1.Value = intMyVal
prm1.Direction = ParameterDirection.Input
prm1.SourceVersion = DataRowVersion.Current
cmdRoles.Parameters.Add(prm1)

Dim dsNames As New DataSet
Dim da As New OracleDataAdapter(cmdRoles)
da.Fill(dsRoles) <-- fails here. when executing the command.

I do not how to make this work. The oracle column is NUMBER SIZE 3, SCALE
0.
Any help would be appreciated.
--
Mike Logan

Nov 18 '05 #2
OracleParameter.ParameterName must comply with Oracle "bind variable" syntax
rules: 1) lexical requirement is-- starts with a letter and then can be
letter, numbers, $, _, or # up to length 30 and 2) when used in query syntax
is preceded by a colon(:)

so, query should be "select from table where numcol = :val"
and then construction and filling of parameter should be:

Dim prm1 As New OracleParamet("val", OracleType.Int32)
prm1.Value = intMyVal
cmdRoles.Parameters.Add(prm1)
note: it doesn't seem to make any sense to use a databinding property on a
parameter whose value is supplied programaticaly. Also, you can save
yourself trouble by using the OracleType that is most directly related to
your actual program variable type (integer or System.Int32). The size of the
Oracle data column is of no importance in this case since you are just
comparing an integer value to ones found within the column, although you know
nothing in the column can exceed 999. But OracleType.Number actually
corresonds most closely to System.Decimal, not System.Int32. In any event,
type checking and/or type consistency will never substitute for bounds
checking.


"Mike" wrote:
I get this error when trying to use a paramter on a dynamic sql statement.
What am I doing wrong.

Exception Details: System.Data.OracleClient.OracleException: ORA-01036:
illegal variable name/number

Here is the code:

Dim strSQL As String
Dim intMyVal as integar = 5
strSQL = "SELECT * FROM TABLE WHERE(NUMBERCOL = @VAL)"

Dim oOracleConn As New OracleConnection(connstring)
If oOracleConn.State = ConnectionState.Closed Then
oOracleConn.Open()
End If

Dim cmdRoles As New OracleCommand(strSQL, oOracleConn)
cmdRoles.CommandType = CommandType.Text

Dim prm1 As New OracleParameter("@VAL", OracleType.Number)
prm1.Size = 3
prm1.Scale = 0
prm1.Value = intMyVal
prm1.Direction = ParameterDirection.Input
prm1.SourceVersion = DataRowVersion.Current
cmdRoles.Parameters.Add(prm1)

Dim dsNames As New DataSet
Dim da As New OracleDataAdapter(cmdRoles)
da.Fill(dsRoles) <-- fails here. when executing the command.

I do not how to make this work. The oracle column is NUMBER SIZE 3, SCALE 0.
Any help would be appreciated.
--
Mike Logan

Nov 19 '05 #3

I get this error when trying to use a paramter on a dynamic sql statement.
What am I doing wrong.

Exception Details: System.Data.OracleClient.OracleException: ORA-01036:
illegal variable name/number

Here is the code:

Dim strSQL As String
Dim intMyVal as integar = 5
strSQL = "SELECT * FROM TABLE WHERE(NUMBERCOL = @VAL)"

Dim oOracleConn As New OracleConnection(connstring)
If oOracleConn.State = ConnectionState.Closed Then
oOracleConn.Open()
End If

Dim cmdRoles As New OracleCommand(strSQL, oOracleConn)
cmdRoles.CommandType = CommandType.Text

Dim prm1 As New OracleParameter("@VAL", OracleType.Number)
prm1.Size = 3
prm1.Scale = 0
prm1.Value = intMyVal
prm1.Direction = ParameterDirection.Input
prm1.SourceVersion = DataRowVersion.Current
cmdRoles.Parameters.Add(prm1)

Dim dsNames As New DataSet
Dim da As New OracleDataAdapter(cmdRoles)
da.Fill(dsRoles) <-- fails here. when executing the command.

I do not how to make this work. The oracle column is NUMBER SIZE 3, SCALE 0.
Any help would be appreciated.
--
Mike Logan


User submitted from AEWNET (http://www.aewnet.com/)
Nov 19 '05 #4
Hi Mike:

Change ":" instead of "@"

Remember that Oracle use the ":" symbol to identify parameters into the SQL parametrized statements.

I hope this helps

I get this error when trying to use a paramter on a dynamic sql statement.
What am I doing wrong.

Exception Details: System.Data.OracleClient.OracleException: ORA-01036:
illegal variable name/number

Here is the code:

Dim strSQL As String
Dim intMyVal as integar = 5
strSQL = "SELECT * FROM TABLE WHERE(NUMBERCOL = @VAL)"

Dim oOracleConn As New OracleConnection(connstring)
If oOracleConn.State = ConnectionState.Closed Then
oOracleConn.Open()
End If

Dim cmdRoles As New OracleCommand(strSQL, oOracleConn)
cmdRoles.CommandType = CommandType.Text

Dim prm1 As New OracleParameter("@VAL", OracleType.Number)
prm1.Size = 3
prm1.Scale = 0
prm1.Value = intMyVal
prm1.Direction = ParameterDirection.Input
prm1.SourceVersion = DataRowVersion.Current
cmdRoles.Parameters.Add(prm1)

Dim dsNames As New DataSet
Dim da As New OracleDataAdapter(cmdRoles)
da.Fill(dsRoles) <-- fails here. when executing the command.

I do not how to make this work. The oracle column is NUMBER SIZE 3, SCALE 0.
Any help would be appreciated.
--
Mike Loga


User submitted from AEWNET (http://www.aewnet.com/)
Nov 19 '05 #5

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

Similar topics

3
by: jonathan | last post by:
hey all, I'd like to implement an application that is truly dynamic: the components are not only just known at runtime, but also the components are unknown at runtime: ie: some don't even ship...
1
by: Guinness Mann | last post by:
When you guys talk about "dynamic SQL," to what exactly are you referring? Is dynamic SQL anything that isn't a stored procedure? Specifically, I use ASP.NET to communicate with my SQL Server...
4
by: Scott Lyons | last post by:
Hey all, Can someone help me figure out how to pass a dynamic array into a function? Its been giving me some trouble, and my textbook of course doesnt cover the issue. Its probably something...
8
by: Sandy Pittendrigh | last post by:
I have a how-to-do-it manual like site, related to fishing. I want to add a new interactive question/comment feature to each instructional page on the site. I want (registered) users to be able...
13
by: salad | last post by:
Operating in A97. I didn't receive much of a response conserning Pivot tables in Access. Pivot tables are nice, but a CrossTab will work for me too. Using a Pivot table, one is actually...
7
by: Jo | last post by:
Hi, How can i differentiate between static and dynamic allocated objects? For example: void SomeFunction1() { CObject *objectp = new CObject; CObject object;
3
by: Mark S. | last post by:
As I understand it, C# doesn't offer dynamic variable names. Below is my attempted workaround. Is what I'm doing possible? FYI, I already read all the "why in the world do you need dynamic...
28
by: sturlamolden | last post by:
On Monday Microsoft announced a new runtime for dynamic languages, which they call "DLR". It sits on top of the conventional .NET runtime (CLR) and provides services for dynamically typed...
20
by: sirsnorklingtayo | last post by:
hi guys please help about Linked List, I'm having trouble freeing the allocated memory of a single linked list node with a dynamic char* fields, it doesn't freed up if I use the FREE()...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.