缺少参数名称,通过代码执行Function时

时间:2014-06-07 08:35:33

标签: vb.net function postgresql stored-procedures

我正在尝试执行以下代码

 Dim transaction As PgSqlTransaction
    Dim command As New PgSqlCommand
    Dim paramLastNo As PgSqlParameter = command.Parameters.Add("funcUpdategtab03", PgSqlType.Int)
    command.Connection = Myconnstr
    Myconnstr.Open()
    command.Transaction = transaction
    transaction = command.Connection.BeginTransaction()
    Try
        command.CommandText = _
        "select funcUpdategtab03(" & SORD & "," & gintAcYrId & "," & gintBranchId & ");"
        command.ExecuteScalar()
        updateGtab03 = paramLastNo.Value
        transaction.Commit()

        Return updateGtab03
    Catch ex As Exception
        transaction.Rollback()
        MsgBox(ex.Message, MsgBoxStyle.Information, "RStari9 - updateGtab03")
    Catch ex As Exception
        transaction.Rollback()
        MsgBox(ex.Message, MsgBoxStyle.Information, "RStari9 - updateGtab03")
    Finally
        Myconnstr.Close()
    End Try

我创建的函数是

    CREATE OR REPLACE FUNCTION funcupdategtab03(ivrid integer, iacyrid integer, ibranchid integer)
  RETURNS integer AS
$BODY$
declare id_val int;
BEGIN
   UPDATE GTAB03 SET lastno=lastno+1 where vrid=ivrid and acyrid=iacyrid and BranchID=ibranchid RETURNING lastno into id_val;

return id_val;
END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
  • 上述功能用于更新表格 我得到的错误是
  

错误缺少参数名称。

1 个答案:

答案 0 :(得分:1)

您已创建输入参数并尝试将其用作输出参数。查询中根本不使用该参数,因此无法获取值,并且忽略从查询中实际返回的结果。

删除参数,并从ExecuteScalar方法获取结果:

updateGtab03 = command.ExecuteScalar()

但是,您应该考虑使用三个输入值的参数,而不是将它们连接到查询中。