[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Passing a variable number of parameters to a function

Posted on 2015-01-28
2
Medium Priority
?
69 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

656 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