从PostgreSQL中的存储过程获取返回值

时间:2021-11-07 02:20:34

I have a stored procedure in PostgreSQL:

我在PostgreSQL中有一个存储过程:

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

RETURN FALSE;

 END;
 $BODY$
 LANGUAGE 'plpgsql' VOLATILE

From ado.net I need to retrieve the return value. I try to do the following:

从ado.net我需要检索返回值。我尝试执行以下操作:

   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 does not work telling me that the type DBNull cannot be converted to Boolean.
Any ideas?

不幸的是,这无法告诉我类型DBNull无法转换为布尔值。有任何想法吗?

1 个解决方案

#1


Try using ExecuteScalar instead of ExecuteNonQuery. I seem to recall that ExecuteNonQuery doesn't return a result either.

尝试使用ExecuteScalar而不是ExecuteNonQuery。我似乎记得ExecuteNonQuery也没有返回结果。

#1


Try using ExecuteScalar instead of ExecuteNonQuery. I seem to recall that ExecuteNonQuery doesn't return a result either.

尝试使用ExecuteScalar而不是ExecuteNonQuery。我似乎记得ExecuteNonQuery也没有返回结果。