Tables In Drop Down List Boxes?

Is it possible to show a table for a SQL Server in a Drop Down List box?
[72 byte] By [WoFe] at [2007-12-23]
# 1

Do you mean is it possible to list the contents of a table in a drop down?

Or show a list of tables?

Either way the answer is yes. You could for example simly bind a dataset containing the required data to the drop down.

JanHyde at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2

You can show the field contents of a SQL table in a drop down list. A drop down list shows a single item whereas a SQL table contains many different fields.

So you have two options here - use a control which can show multiple items - such as a datagridview control which enables you to show all the contents of a table.

Decide on which field from the database table you wish to show in the drop down list (ie. one field from the table mapping to one drop down list)

In you select statement populate a field which is a single text field that is an amalgamation of the other fields in the table perhaps separated by commas - this field returned in the dataset is a single item which can be shown in a single dropdown list - therefore showing all the fields for a record in a single dropdown list of all the records in the database table.

I'd probably suggest using the datagridview and simply creating a dataset - and using this as the datasource for the datagridview.

spotty at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
I have beening using SQL statements to populate my

drop down list boxes but i can't get one to work for populating a table

in a drop down list box... . someone told me i

might have to use COALESCE to get it to work but i want it to be a table..

now when they do choose a value i don't need the whole record to come

back to me just the primary key of that record.

okay the form i use this sqlcommand to pull the needed information...

Code:

SELECT VendorNumber, VendorCompanyName, VendorBillingCode, VendorArea

FROM tblPE_Vendor

ORDER BY VendorCompanyName

then i was using to populate the ddl was the dreader

only reading one collum... is it possible to have the dreader to show

the entire select statment and just not one collum?

here is the code i was using.. but it only shows one collum of the table.. i need it to show the entire table.

Code:

If Not IsPostBack Then

Dim dreader As SqlClient.SqlDataReader

SqlConnection1.Open()

dreader = SqlLoadOpCenter.ExecuteReader()

Dim firstrow As Boolean = True

While dreader.Read()

ddlOperationCenter.Items.Add(New ListItem(dreader("Op_center_abbrev").ToString()))

End While

dreader.Close()

SqlConnection1.Close()

End If

But from the sounds of it.. it doesn't even like i can continue my newbie ways and continue using the SQL command stuff....


WoFe at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4

You could modify you code

ddlOperationCenter.Items.Add(New ListItem( dreader("VendorNumber").ToString() & " " & dreader("VendorCompanyName").ToString() & " " & dreader("VendorBillingCode").ToString() & " " & dreader("VendorAread").ToString() ))

So this would show all the columns in this table - you could make this a little more generic by iterating through the columns in the dreader record.

Or you could change the SQL statement - so you create a field in the SQL dataset which is a combination of the other fields.

But the answer is that the DDL will contain a single item that is being displayed. You can create a single item in your VB code, in SQL code but the ddl is not a multicolumn, which you would need for displaying a tables contents - if you want this capability then you should look to other controls such as datagridview, listview etc.

But as this appears to be a web application - I might suggest discussing this on the ASP.NET forums ( forums.asp.net) as they will probably give you some specific controls which may be more suitable.

spotty at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...