1

i have trouble calling a function from VB with IDBcommand which returns a integer value

        param1 = dbfactory.CreateParameter("param1", DbType.AnsiString)
        param1.Value = sIban
        param1.Direction = ParameterDirection.Input
        param1.Size = 1000
        param2 = dbfactory.CreateParameter("param2", DbType.AnsiString)
        param2.Value = sNid
        param2.Direction = ParameterDirection.InputOutput
        param2.Size = 1000
        param3 = ´dbfactory.CreateParameter("param3", DbType.AnsiString)
        param3.Value = sKto
        param3.Direction = ParameterDirection.InputOutput
        param3.Size = 1000
        ret_value = dbfactory.CreateParameter(Nothing, DbType.Int16)
        ret_value.Size = 1000
        ret_value.Direction = ParameterDirection.ReturnValue
        cmd.CommandText = "Func1"
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Parameters.Add(param1)
        cmd.Parameters.Add(param2)
        cmd.Parameters.Add(param3)
        cmd.Parameters.Add(ret_value)
        cmd.Connection = conn
        cmd.ExecuteNonQuery()

The header from my function looks like this:

CREATE OR REPLACE FUNCTION Func1( param1 VARCHAR(50), param2 VARCHAR(50), param 3 VARCHAR(50))RETURNS INTEGER

I get an exception that no procedure could be found.

Does anybody have any idea? I have been searching for a while now.

Thanks

4

1 回答 1

0

您创建了一个带有 3 个参数的函数,但调用了一个带有 4 个参数的存储过程——难怪它会失败,因为它们是不同的对象,并且您以不同的方式调用它们。

我对 .Net 的东西不是很熟悉,但一般来说,您应该在查询的上下文中调用 UDF:

select Func1(?, ?, ?) from sysibm.sysdummy1

VALUES声明

values Func1(?, ?, ?)

在这两种情况下,您都会得到一个结果集,您可以从中获取函数返回的值。检查手册中的代码示例

于 2013-08-29T14:59:28.877 回答