Create list from SqlDataReader

Hello experts,

How can I create a list from an ADO query that will show in a response.write format?
In my example below I don't get any text just a string like below:
"System.Collections.Generic.List`1[System.String]"
Basically all I'm trying to do is to return all records in the list table and write contents as a list.
Any help would be greatly appreciated.


Dim emListSelect As String
            emListSelect = "SELECT  list.id, list.type, list.store, list.product, list.qty, list.price, list.fk_Cat, list.listDTE, "
            emListSelect &= "ProdStore.store_name FROM list INNER JOIN ProdStore ON list.store = ProdStore.store_id "
            emListSelect &= "ORDER BY list.listDTE DESC"
            Dim emListConnString As String = WebConfigurationManager.ConnectionStrings("ShopConnection").ConnectionString
            Dim emListConn As New SqlConnection(emListConnString)
            Dim emListCommand As New SqlCommand(emListSelect, emListConn)

            Dim readerList As SqlDataReader
            Dim returnData As List(Of String) = New List(Of String)
            emListConn.Open()
            readerList = emListCommand.ExecuteReader()
            While readerList.Read()
                returnData.Add(readerList("product").ToString())
            End While
            Response.Write(returnData.ToArray())
            emListConn.Close()

Open in new window

LVL 1
PhosphorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Evan CutlerVolunteer Chief Information OfficerCommented:
Response.Write(returnData.ToArray())

You can create an IList<String> and insert your data into that.

ie. look at this:  http://www.java2s.com/Code/VB/Generics/GenericStringList.htm

Then the IList can be used in a for-each statement and done with what you want.
You can even do a join and output as a comma-delineated list.

0
PhosphorAuthor Commented:
Thanks anyway arcee123, I figured out what I needed to do:

Created a bulleted list named bl and used that as a control to facilitate
a RenderControl to a string.

Dim bl1 As New BulletedList
            Dim readerList As SqlDataReader
            readerList = emListCommand.ExecuteReader()
            Do While readerList.Read()
                Dim newItem As New ListItem()
                newItem.Text = readerList("product")
                newItem.Value = readerList("product").ToString()
                bl1.Items.Add(newItem)
            Loop
            emListConn.Close()
            Dim SB As New StringBuilder()
            Dim SW As New StringWriter(SB)
            Dim htmlTW As New HtmlTextWriter(SW)
            bl1.RenderControl(htmlTW)
            Dim htmlList As String = SB.ToString()

I tried it several ways but this was drop-dead easy.
I didn't mention that the end use was to email the list on an inserted function.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PhosphorAuthor Commented:
arcee 123's reply was pointing to a block of java code.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.