Link to home
Start Free TrialLog in
Avatar of VonGeist
VonGeist

asked on

How to build temp table and bind to a list box

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")
        dCart.Columns.Add("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)
            cn.Open()
            leftcnt = 0
            Using rdr As Data.SqlClient.SqlDataReader = cmd.ExecuteReader()
loopit:
                If leftcnt > 30 Then
                    GoTo bindit
                End If
                rdr.Read()
                If rdr.HasRows Then
                    drow = dCart.NewRow()
                    drow("proddesc") = rdr("id") & "..." & rdr("Product") & "..." & rdr("description")
                    leftcnt = leftcnt + 1
                    dCart.Rows.Add("proddesc")
                Else
                    GoTo bindit
 
                End If
                GoTo loopit
bindit:
                
                LeftBox.DataSource = dCart
                LeftBox.DataBind()
            End Using
            cn.Close()
        End Using
thatsit:
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial