|
-
Nov 26th, 2007, 06:08 PM
#1
Thread Starter
New Member
Oracle and Parameters
Hi folks,
I've a dubt.
If I use a query with named parameters like this :
Code:
string query = "insert into test(name,age) values(:name,:age)"
where name is a varchar2 and age is a number(3), If I do this :
Code:
int age=29;
string name="Phil";
OracleCommand myComm = new OracleCommand(sql, myConn);
myComm.Parameters.Add("age", OracleDbType.Int32,ParameterDirection.Input);
myComm.Parameters.Add("name", OracleDbType.Varchar2, ParameterDirection.Input);
myComm.Parameters["age"].Value = age;
myComm.Parameters["name"].Value = name;
int rowsAffected = myComm.ExecuteNonQuery();
I get an error, because the order is wrong, and it tries to put the name in the number column .
So, is the order the only way to associate the data column ???
Thank you 
P.S. : Oracle 9i and ODP.Net
-
Nov 27th, 2007, 10:13 AM
#2
Re: Oracle and Parameters
Are you sure the order is causing the error?
What is the wording of the error?
-
Nov 27th, 2007, 10:59 AM
#3
Re: Oracle and Parameters
My personal option is I would add the parameters in the same order they are in the statement (add name then add age). Yes I know it should work either way but I find it always works if I add them in the same order (at least for Oracle)
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Nov 27th, 2007, 11:04 AM
#4
Re: Oracle and Parameters
 Originally Posted by GaryMazzone
My personal option is I would add the parameters in the same order they are in the statement (add name then add age). Yes I know it should work either way but I find it always works if I add them in the same order (at least for Oracle)
I agree with this completely, however, I don't believe the order should generate an error, which leads me to believe there is other evil afoot here.
-
Nov 27th, 2007, 11:46 AM
#5
Thread Starter
New Member
Re: Oracle and Parameters
 Originally Posted by Hack
Are you sure the order is causing the error?
What is the wording of the error?
Yes, because if you change the order it works well (it's only a very simple example, I get this error in a code that use hashtable to store the parameter but it doesn't preserve the order).
So I only want to know if the name of the parameter it's a big joke and it doesn't meaning nothing and there isn't any relationship with the query parameters.
So I can have a query like : select ... where a=:a and b=:b
and call the add parameter called x and y.
Sorry for my poor english
-
Nov 27th, 2007, 03:08 PM
#6
Re: Oracle and Parameters
I don't know if this is the case for Oracle, but for Access database, you must add the parameters in the exact same order as the query string... However, from what you've experiencing, I would say that is the case too.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|