tags:

views:

41

answers:

1

Hello guys!

I have built a common app that works with PostgreSQL and should work on Oracle.

However i'm getting strange errors when inserting records through a parametrized query.

My formatted query looks like this:

"INSERT INTO layer_mapping VALUES (@lm_id,@lm_layer_name,@lm_layer_file);"

Unlike Npgsql which documents how to use the parameters, i could not found how Oracle "prefers" them to be used. I could only find :1, :2, :3, for example.

I do not wanto use sequential parameters, i want to use them in a named way.

Is there a way to do it? Am i doing something wrong?

Thanks

+1  A: 

You can use named parameters with ODP.NET like so:

using (var cx=new OracleConnection(connString)){
   using(var cmd=cx.CreateCommand()){
      cmd.CommandText="Select * from foo_table where bar=:bar";
      cmd.BindByName=true;
      cmd.Parameters.Add("bar",barValue);
      ///...
   }
}
Josh Bush
Thank you Josh! What about for a insert? I do not need to qualify the columns names, do i?the real pain here is that BindByName. Npgsql does not need or require that variable to be set!
George
For inserts you can use "INSERT INTO table_name values(:foo,:bar)" or "INSERT INTO table_name(foo,bar) values(:foo,:bar)" I prefer the last way in case the table structure changes in the future.
Josh Bush
Thanks :D Darn that BindByName! :P
George