Oracle Parameters with ODP.Net

cfirex

New member
Joined
Nov 27, 2007
Messages
1
Hi folks,

Ive 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 ??? :eek:

Thank you :)

P.S. : Oracle 9i and ODP.Net
 
have you tried this?

Code:
int age=29;
string name="Phil";

OracleCommand myComm = new OracleCommand(sql, myConn);
myComm.Parameters.Add("age", OracleDbType.Int32,ParameterDirection.Input);
myComm.Parameters["age"].Value = age;
myComm.Parameters.Add("name", OracleDbType.Varchar2, ParameterDirection.Input);
myComm.Parameters["name"].Value = name;
            
int rowsAffected = myComm.ExecuteNonQuery();
 
Back
Top