Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi folks,

 

I've a dubt.

 

If I use a query with named parameters like this :

 

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 :

 

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

Posted

have you tried this?

 

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();

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...