Create list from SqlDataReader

Posted on 2011-10-27
Last Modified: 2012-05-12
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:
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.type,, list.product, list.qty, list.price, list.fk_Cat, list.listDTE, "
            emListSelect &= "ProdStore.store_name FROM list INNER JOIN ProdStore ON = 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)
            readerList = emListCommand.ExecuteReader()
            While readerList.Read()
            End While

Open in new window

Question by:Phosphor
    LVL 9

    Expert Comment

    by:Evan Cutler

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

    ie. look at this:

    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.

    LVL 1

    Accepted Solution

    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()
                Dim SB As New StringBuilder()
                Dim SW As New StringWriter(SB)
                Dim htmlTW As New HtmlTextWriter(SW)
                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.
    LVL 1

    Author Closing Comment

    arcee 123's reply was pointing to a block of java code.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
    This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    728 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

    17 Experts available now in Live!

    Get 1:1 Help Now