Link to home
Start Free TrialLog in
Avatar of prosit
prositFlag for United States of America

asked on

Passing a variable number of parameters to a function

Hi,

Why doesn't this work:

 For Each strline As String In my852File.Split(vbCrLf)
            Dim line852() = strline.Split(",")
            Dim parms(24) As SqlParameter
            parms(cnt) = New SqlParameter("@" + ColNames(cnt), line852(cnt))
            clsData.SQLInsert(parms)

' parms above is hightlighted with this error: Value of type '1-dimensional array of System.Data.SqlClient.SqlParameter' cannot be converted to 'System.Collections.Generic.List(Of System.Data.SqlClient.SqlParameter)'.


            cnt += 1
Next

Open in new window


sqlInsert:

 Public Function SQLInsert(ByVal ParameterValues As List(Of SqlParameter)) As Boolean
        Try
            Dim ConnectionStr As New SqlConnection(myVars.GetSQLString)
            Dim sqlCMD As New SqlCommand()
            For Each parm As SqlParameter In ParameterValues
                sqlCMD.Parameters.Add(parm)
            Next

            sqlCMD.CommandType = CommandType.StoredProcedure

            sqlCMD.ExecuteNonQuery()
            
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function
End Class

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of prosit

ASKER

Perfect thanks!