Getting return value from stored procedure in PostgreSQL

I have a stored procedure in PostgreSQL:

CREATE OR REPLACE FUNCTION dosmth()
RETURNS boolean AS
$BODY$
BEGIN

RETURN FALSE;

 END;
 $BODY$
 LANGUAGE 'plpgsql' VOLATILE

      

From ado.net, I need to get the return value. I am trying to do the following:

   DbCommand cmd = DBTemplate.CreateStoredProcedureCommand(dbConnection, "dosmth");

   cmd.Parameters.Add(DBTemplate.CreateParameter(System.Data.DbType.Boolean,
                "@RETURN_VALUE", System.Data.ParameterDirection.ReturnValue));

   DBTemplate.ExecuteNonQuery(cmd);
   Boolean bl = Convert.ToBoolean(cmd.Parameters["@RETURN_VALUE"].Value);

      

Unfortunately this doesn't work, telling me the type DBNull

cannot be converted to Boolean

.
Any ideas?

0


a source to share


1 answer


Try using ExecuteScalar

instead ExecuteNonQuery

. I think I remember that ExecuteNonQuery

not the return

same result.



+1


a source







All Articles