Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2003
    Duluth MN
    3,864 Question

    When calling data from a database, how can you get that data to be piped into a DropDownList?

    I'm looking at the DataBinding stuff, and DataGrid stuff, but I'm not seeing any particular way to do this.

    I have this code to get the data from the database into a datagrid, but how can I get it into a dropdown list? Or how can I get it into an array, rather than a datagrid?

    Dim MyConnection As SqlConnection = New SqlConnection("server=server;database=db;uid=user;pwd=pass")
    Dim MyCommand As SqlCommand = New SqlCommand("select o.offid, o.offname, o.location from Office as o", myConnection)
    Dim dr As SqlDataReader

    dr= MyCommand.ExecuteReader()
    MyDataGrid.DataSource = dr


  2. #2
    Join Date
    Dec 2002
    NY, NY
    drop down list ..
    <select name="XX">
    <option>[VALUE FROM DB]</option>
    Its just a simple loop..
    If its what i think your talking about

  3. #3
    Join Date
    Aug 2000
    Redmond, WA
    The best way to do this (assuming you're using an ASP.NET Server Control for the drop down list) is to use Data Binding. To do that you'd set the DataSource for the drop down list to the SqlDataReader, set the DataTextField property on the Drop Down List to the name of the column that is the Text field of the list and the DataValueField property on the drop down list to the name of the column that contains the actual values. Then call Databind on the control. The data grid in your sample code is not needed.

    I hope this helps. Let me know if you have any other questions. I normally deal with C#, but some of this stuff is similar enough.
    Chris Spangler
    [email protected]

  4. #4
    to follow-up what Chris said...the VB DataBind3.aspx example might help.

    good luck!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts