?
Solved

ASP.NET Combobox Data

Posted on 2007-07-19
3
Medium Priority
?
206 Views
Last Modified: 2013-11-26
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
0
Comment
Question by:lrbrister
  • 2
3 Comments
 
LVL 15

Expert Comment

by:Solar_Flare
ID: 19527165
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
 

Author Comment

by:lrbrister
ID: 19527228
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
 
LVL 15

Accepted Solution

by:
Solar_Flare earned 2000 total points
ID: 19527914
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

807 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