Solved

ASP.NET - error - Value of type 'System.Collections.Generic.List(Of String)' cannot be converted

Posted on 2011-03-09
3
1,805 Views
Last Modified: 2012-05-11

the goal of this code is that on postback from the user selecting from a drop down menu...will go and find all phone numbers and
populate a grid...however, I get the following error:
--------------
line 81:

   " and  TO_NUMBER in ('" & String.Join(",", myList) & ")"
in the IDE...it has mylist underlined....

when I put the cursor overmylistThen it displays this error:
Value of type 'System.Collections.Generic.List(Of String)' cannot be converted to '1-dimensional array of String'.




Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim DDL_val As String
        Dim flag As String
        Dim TC_ID As String
        
        TC_ID = Session("SessionTC_ID")
        DDL_val = DropDownList1.Text
        flag = "dataset"
        
        Session("sessionDDL") = DropDownList1.Text
        
        
        
        ' -----------------------------------------------------------------------------
        ' DHAEST SOULTION FROM EE...
        ' http://www.experts-exchange.com/Programming/Languages/.NET/Q_26843829.html
        '
        
        
        
        Dim myList As List(Of String) = New List(Of String)
        
        Try

            
            Dim MyDropDown As DropDownList
           
            Dim myArray As New ArrayList()
            Dim dataReader As SqlDataReader
            Dim x As Integer = 0
            Dim sqlConnection As String
            
            TC_ID = Session("SessionTC_ID")
            MyDropDown = DropDownList1
            
               
            Using sqlConn As New SqlConnection
                sqlConnection = "Data Source=xx.xx.xx.xx;Initial Catalog=dcdff;Trusted_connection=true;"
                sqlConn.ConnectionString = sqlConnection
                Dim SQLstring As String = "SELECT * FROM campaign WHERE TC_ID = '" & TC_ID & "'" & _
   " AND campaign_name = '" & Session("sessionCAMP_NAME") & "'"
          
                sqlConn.Open()
                Using command As New SqlCommand(SQLstring, sqlConn)
                    dataReader = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
                    If dataReader.HasRows Then
                        Do While dataReader.Read()
                            myList.Add(dataReader("TO_NUMBER").ToString())
                        Loop
                        
                    End If
                    dataReader.Close()
                    sqlConn.Close()
                End Using
            End Using
            
            myArray.Sort()

            MyDropDown.DataSource = myArray
            MyDropDown.DataBind()
        Catch ex As Exception
           
        End Try
          
        
               
        ' --------------------------------
        ' POPULATE THE TEXTBOX CONTROL..ON SELECTION FROM DROPDOWNLIST
        ' --------------------------------
        Try
            Dim Go_Message As TextBox
            Dim sqlConnection As String
          

            Using sqlConn As New SqlConnection
                sqlConnection = "Data Source=xx.xx.xx.xx;Initial Catalog=dffgxt;Trusted_connection=true;"
                sqlConn.ConnectionString = sqlConnection
                ' Dim SQLstring As String = "SELECT * FROM message_queue_recieve WHERE TC_ID = '" & TC_ID & "' and campaign_name = '" & DDL_val & "'" & _
                '" TO_NUMBER = '" & Session("sessonTO_NUMBER") & "'"
                Dim SQLstring As String = "SELECT * FROM message_queue_recieve WHERE TC_ID = '" & TC_ID & "'" & _
                " and  TO_NUMBER in ('" & String.Join(",", myList) & ")"
               
                Dim TblAdaptar As New SqlDataAdapter(SQLstring, sqlConn)
                Dim Tbl As New DataSet
                Tbl.Clear()
                Try
                    TblAdaptar.Fill(Tbl)
                    Me.GridView1.DataSource = Nothing
                    Me.GridView1.DataSource = Tbl
                    Me.GridView1.DataBind()
                Catch ex As Exception
                End Try
            End Using
        Catch ex As Exception
        End Try
        
        
        ' more code...

Open in new window

0
Comment
Question by:GlobaLevel
  • 2
3 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35084387
You need to convert your list to an array.

i.e.
string.Join(",", myList.ToArray())

Open in new window

0
 
LVL 10

Expert Comment

by:John Claes
ID: 35084450
that is indeed the reason :


Line 21:
        Dim myList As List(Of String) = New List(Of String)

Line 81 :
               " and  TO_NUMBER in ('" & String.Join(",", myList) & ")"


A generic List is indeed not accepted by the String.Join method

Use for Line 81 the folowig
               " and  TO_NUMBER in ('" & String.Join(",", myList.AsEnumerable()) & ")"

regards

poor beggar
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 35084480
It can't use IEnumerable<> either! So as I said in my first post you need to call ToArray() on your List<>.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Replace &lt; with < 14 54
Visual Studio 2015 Source Code Control 10 26
Not seen Link button 5 0
Gridview alignment 1 0
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

919 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now