I am trying to use Npgsql to call a function (stored procedure) that takes a CHARACTER parameter as a parameter, but it does not work. If I declare the same function with no parameters or with an INTEGER parameter, I get the desired result factors. When I declare a CHARACTER parameter, it stops working. What's wrong?
Here is the code of my function:
CREATE OR REPLACE FUNCTION testrefcursor1(in xxx character varying(10)) RETURNS SETOF refcursor AS $$ DECLARE ref1 refcursor; ref2 refcursor; BEGIN OPEN ref1 FOR SELECT * FROM accounts; RETURN NEXT ref1; OPEN ref2 FOR SELECT * FROM accounts; RETURN NEXT ref2; RETURN; END; $$ LANGUAGE plpgsql;
And here is the C # code that I use:
var connection = new Npgsql.NpgsqlConnection(connectionString.ConnectionString); connection.Open(); var trans = connection.BeginTransaction(); var command = new Npgsql.NpgsqlCommand("testrefcursor1", connection); command.CommandType = System.Data.CommandType.StoredProcedure; var parameter = command.CreateParameter(); parameter.ParameterName = "xxx"; parameter.DbType = System.Data.DbType.String; parameter.Value = "10"; command.Parameters.Add(parameter); var da = new Npgsql.NpgsqlDataAdapter(command); var ds = new System.Data.DataSet(); da.Fill(ds); trans.Commit(); connection.Close();
I already tried declaring the parameter as CHARACTER, CHARACTER (10), CHARACTER VARYING and CHARACTER VARYING (10) ...
EDIT: I am not getting an error message, but instead of getting the expected result set, I get an empty result set with one column that has the same name as the function I'm trying to call.
source share