Results 1 to 6 of 6

Thread: Oracle and Parameters

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    6

    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

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Oracle and Parameters

    Are you sure the order is causing the error?

    What is the wording of the error?

  3. #3
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    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

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Oracle and Parameters

    Quote 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.

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    6

    Re: Oracle and Parameters

    Quote 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

  6. #6
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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
  •  



Click Here to Expand Forum to Full Width