在VB.net中''参数太多了

时间:2015-10-20 01:51:48

标签: vb.net

我正在尝试从列表字段中保存有多个数据,如何一次保存所有数据? 我试过这段代码

    Dim detail As New Detail
    Dim detailBr As New DetailBridge
    Dim i As Integer

    For i = 0 To lstProduct.Items.Count - 1
        detail = detailBr.Insert(Convert.ToInt32(ddlGroup.SelectedValue), lstProduct.Items(i).Value) 'error was here
    Next

但我在lstProduct.Items(i).Value错误中说错误

  

'...'的参数太多

我不确定错误是什么。

任何人都可以帮忙吗?谢谢你的建议。

更新:detailBr是类,代码是

Public Function Insert(ByVal GroupID As Integer, ByVal ProductID As String) As Boolean
    Dim iResult As Integer
    Dim arrColumn() As String = {"GroupID", "ProductID"}
    Dim arrValue() As Object = {GroupID, ProductID}

    oConn.Open()
    Dim SQLString As String = GenInsert("DetailGroup", arrColumn, arrValue)

    Try
        iResult = SCommand.Execute(SQLString, oConn)
    Catch ex As Exception
        Throw ex
    Finally
        oConn.Close()
    End Try

    If iResult > 0 Then
        Return True
    Else
        Return False
    End If
End Function

1 个答案:

答案 0 :(得分:0)

这里的问题是GenInsert函数。它的最后两个参数是数组。

Dim arrColumn() As String = {"GroupID", "ProductID"}
Dim arrValue() As Object = {GroupID, ProductID}

Dim SQLString As String = GenInsert("DetailGroup", arrColumn, arrValue)
  

一个过程只能定义一个参数数组,它必须是过程定义中的最后一个参数。 MSDN

简单来说,在GenInsert函数中只能有一个参数作为数组arrColumn或arrValue

但是,要解决当前问题,您可以使用二维数组作为参数,如passing-two-dimensional-array-through-functionsMSDN: Arrays as Return Values and Parameters