ASP.NET Combobox Data

I'm populating a combobox with the code below.  How do I add the item " - Select All - " to the top of the list?

 Public Sub getZipCode()
        Dim objConn As SqlConnection
        objConn = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("strConn"))
        Dim oCom2 As SqlCommand = New SqlCommand
        oCom2.Connection = objConn
        objConn.Open()
        Dim sSQL As String
        sSQL = "Select [zipcode] "
        sSQL = sSQL & "from tblMasterList where zipcode <>''"
        sSQL = sSQL & "group by [zipcode] "
        sSQL = sSQL & "order by [zipcode]"
        oCom2.CommandText = sSQL
        'Dim dR As SqlDataReader
        getZip.DataSource = oCom2.ExecuteReader()
        getZip.DataBind()
        oCom2.Dispose()
        objConn.Close()

    End Sub
Larry Bristersr. DeveloperAsked:
Who is Participating?
 
Solar_FlareCommented:
oh lol, that is C# type syntax!

        dim DA as new SqlDataAdapter(oCom2)
        dim dt as new DataTable
        DA.Fill(dt)  '<--- put the results into dt

        'now add the top item
        dim dr as DataRow = dt.NewRow()
        dr(0) = "- Select Item -"
        dt.Rows.InsertAt(dr, 0)

0
 
Solar_FlareCommented:
it would be easier to use a dataadapter to get a table rather than use a cursor

Public Sub getZipCode()
        Dim objConn As SqlConnection
        objConn = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("strConn"))
        Dim oCom2 As SqlCommand = New SqlCommand
        oCom2.Connection = objConn
        objConn.Open()
        Dim sSQL As String
        sSQL = "Select [zipcode] "
        sSQL = sSQL & "from tblMasterList where zipcode <>''"
        sSQL = sSQL & "group by [zipcode] "
        sSQL = sSQL & "order by [zipcode]"
        oCom2.CommandText = sSQL
     
        dim DA as new SqlDataAdapter(oCom2)
        dim dt as new DataTable
        DA.Fill(dt)  '<--- put the results into dt

        'now add the top item
        DataRow dr = dt.NewRow()
        dr(0) = "- Select Item -"
        dt.Rows.InsertAt(dr, 0)

        getZip.DataSource = dt
        getZip.DataBind()
        oCom2.Dispose()
        objConn.Close()

    End Sub
0
 
Larry Bristersr. DeveloperAuthor Commented:
Solar Flare

I'm getting "Datarow is a type and cannot be used in an expression message."

This is an ascx page

DataRow(da = dt.NewRow())   -  Several errors here
        dr(0) = "- Select Item -"
        dt.Rows.InsertAt(dr, 0)
0
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.

All Courses

From novice to tech pro — start learning today.