Vb.net 以string.format插入列表对象作为参数

Vb.net 以string.format插入列表对象作为参数,vb.net,string,ado.net,string.format,Vb.net,String,Ado.net,String.format,我试图将string.format中的列表作为参数传递给SQL语句,但出现以下错误: 索引(从零开始)必须大于或等于零且小于参数列表的大小 我知道,当我列出每个列表成员作为参数时,我可以让它工作,但是我想知道是否有一个快捷方式,这样我就可以使用列表对象作为唯一的参数 谢谢 Public Sub updateSecurityMasterTable(ByVal params As Dictionary(Of String, String)) Dim updateList As New Li

我试图将string.format中的列表作为参数传递给SQL语句,但出现以下错误:

索引(从零开始)必须大于或等于零且小于参数列表的大小

我知道,当我列出每个列表成员作为参数时,我可以让它工作,但是我想知道是否有一个快捷方式,这样我就可以使用列表对象作为唯一的参数

谢谢

Public Sub updateSecurityMasterTable(ByVal params As Dictionary(Of String, String))

    Dim updateList As New List(Of String)

    Try
        updateList.Add(params.Item("ticker"))
        updateList.Add(String.Empty)
        updateList.Add(params.Item("asset_class"))
        updateList.Add(params.Item("sub_class"))
        updateList.Add(params.Item("asset_type"))
        updateList.Add(params.Item("current_price"))
        updateList.Add(params.Item("market_cap"))
        updateList.Add(params.Item("dividend_yield"))
        updateList.Add(params.Item("pe_ratio"))
        updateList.Add(params.Item("eps"))
        updateList.Add(params.Item("sector"))
    Catch ex As Exception
        Throw ex
    End Try


    Dim strSql As New StringBuilder

    strSql.Append("INSERT INTO SecurityMaster ")
    strSql.Append("(ticker, cusip, asset_class, sub_class, asset_type, current_price, market_cap, dividend_yield, pe_ratio, eps, sector) ")
    strSql.Append(String.Format("VALUES (N'{0}', N'{1}', N'{2}', N'{3}', N'{4}', N'{5}', N'{6}', N'{7}', N'{8}', N'{9}', N'{10}')", updateList))

    Try
        If checkConnection() Then
            'Do Nothing
        Else
            Me.createConnection()
        End If

        Using cmdExe As New SqlCeCommand(strSql.ToString(), conn)
            cmdExe.ExecuteNonQuery()
        End Using
    Catch ex As Exception
        Throw ex
    End Try

End Sub
尝试:

尝试:


@皮特也帮了我一把,他做了一些稍微不同但又相关的事情:)。助教@皮特也帮了我一把,他做了一些稍微不同但又相关的事情:)。助教!
String.Format("VALUES (N'{0}', N'{1}', N'{2}', N'{3}', N'{4}', N'{5}', N'{6}', N'{7}', N'{8}', N'{9}', N'{10}')", updateList.ToArray)