We help IT Professionals succeed at work.
Get Started

How to build temp table and bind to a list box

Last Modified: 2013-11-26
I am trying to build a temp table in memory from a swl table.  I would then like to bind it to a list box.  I keep getting system.data.datarow instead of the data.  I have looked at a variety of answers but none of them work.  This is for a web page in vb./net in visual studio.  I want to build a list box that peple can select an item and then move it to another list box.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack Then
            GoTo thatsit
        End If
        Dim dCart As New Data.DataTable("cart")
        Dim dcol As New Data.DataColumn("proddesc")
        Dim drow As Data.DataRow
        Dim tmpcon As String
        Dim leftcnt As Integer
        tmpcon = System.Configuration.ConfigurationManager.AppSettings("WebConnectString")
        Dim conn As New Data.SqlClient.SqlConnection(tmpcon)
        Dim strsql As String
        Using cn As New Data.SqlClient.SqlConnection(conn.ConnectionString)
            strsql = "SELECT Id, Product, Description FROM MasterCoverage ORDER BY Product"
            Dim cmd As New Data.SqlClient.SqlCommand(strsql, cn)
            leftcnt = 0
            Using rdr As Data.SqlClient.SqlDataReader = cmd.ExecuteReader()
                If leftcnt > 30 Then
                    GoTo bindit
                End If
                If rdr.HasRows Then
                    drow = dCart.NewRow()
                    drow("proddesc") = rdr("id") & "..." & rdr("Product") & "..." & rdr("description")
                    leftcnt = leftcnt + 1
                    GoTo bindit
                End If
                GoTo loopit
                LeftBox.DataSource = dCart
            End Using
        End Using
    End Sub

Open in new window

Watch Question
Most Valuable Expert 2012
Top Expert 2014
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE