?
Solved

Passing a variable number of parameters to a function

Posted on 2015-01-28
2
Medium Priority
?
67 Views
Last Modified: 2015-01-28
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

0
Comment
Question by:prosit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 34

Accepted Solution

by:
it_saige earned 2000 total points
ID: 40576075
It's because parms is an array, not a list (two different types of collections).  Use parms.ToList() instead:
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.ToList())
            '''
            '''
            cnt += 1
Next

Open in new window

-saige-
0
 
LVL 2

Author Closing Comment

by:prosit
ID: 40576107
Perfect thanks!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question