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
MyDataGrid.DataSource = dr
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.