Npgsql pass parameters by name to a stored function

0 votes
asked Mar 4, 2010 by jeff

I'm working with code I'm converting to Pgsql working with .NET. I want to call a stored function that has several parameters, but I'd like to bind the parameters by name, like so:

NpgsqlCommand command = new NpgsqlCommand("\"StoredFunction\"", _Connection)
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("param2", value2);
command.PArameters.Add("param1", value1);

Attempts to do this so far look for a function with parameter types matching in the order in which I added the parameters to the collection, not by name.

Is it possible for Npgsql to bind parameters to stored functions by name?

2 Answers

0 votes
answered Mar 5, 2010 by francisco-junior

Currently Npgsql doesn't support pass parameters by name. Although it supports receiving out parameter values by name.

Would you mind to fill a bug report about that? So we can track and implement it.

0 votes
answered Mar 23, 2010 by mr-shoubs

Unfortunately it does not work with store procedure (CommandType.StoredProcedure).

It does with SQL-text command (CommandType.Text). You can use :paramname, plus I think in the latest version you can use parameters.addwithvalue(":paramname", param).

You can also use @paramname with the latest version (like MS Sql Server).

Read section "Using parameters in a query " of this manual for an answer to your original question - but remember what I said above to make your life easier.

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...