Call Stored Procedure with inout parameters in c#

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Call Stored Procedure with inout parameters in c#

İlyas Derse
I tried with inout parameters but it did not work correctly.

here is my procedure :

CREATE OR REPLACE PROCEDURE public.testing ( INOUT x int )
LANGUAGE 'plpgsql'
AS $$
BEGIN
   x := x * 3;
END ;
$$;

my C# code:

public void myMethod2()
        {
            CRUD.con.Open();
            int a = 5;
            using (var cmd = new NpgsqlCommand("call public.testing();", CRUD.con))
            {
                var objParam = new NpgsqlParameter("x", NpgsqlDbType.Integer)
              { Direction = ParameterDirection.Output };
                objParam.Value = 5;
                cmd.Parameters.Add(objParam);
                cmd.ExecuteNonQuery();
                Console.WriteLine(objParam.Value);
            }
            CRUD.con.Dispose();
        }