Click here to Skip to main content
16,021,181 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two Columns contain Separate Value i want to show both of them in one combo box as dropdown list

What I have tried:

VB.NET
Dim cmd As New SqlCommand("  select * from tbl1 where ID   = @ID", con)
cmd.Parameters.AddWithValue("@ID", TextID.Text)
Dim DataAdopter = New SqlDataAdapter(cmd)
Dim dt As New DataTable
DataAdopter.Fill(dt)
ComboProductType.DataSource = dt
If dt.Rows.Count > 0 Then


    ComboProductType.DisplayMember = "Mango"
    ComboProductType.DisplatMember = "Orange"
Posted
Updated 18-Oct-21 22:02pm
v2
Comments
Maciej Los 18-Oct-21 15:07pm    
Sorry, but your question is not clear. Please, be more specific.
Member 14649324 18-Oct-21 15:20pm    
I have a table that contain two columns one columns have for example fruits like Apple Orange Manago and one columns contain vegtables Carrot Tomato,Onion now want combine these two columns values and show as drop downn list in combobox like
Mango
Orange
Tomato
Onion

1 solution

If you want to combine the values from two columns into a single list, use a UNION query.
VB.NET
Dim cmd As New SqlCommnd("SELECT column1 As ProductType FROM YourTable WHERE ID = @ID UNION SELECT column2 As ProductType FROM YourTable WHERE ID = @ID")
cmd.Parameters.AddWithValue("@ID", TextID.Text)

Dim da As New SqlDataAdapter(cmd)
Dim dt As New DataTable
da.Fill(dt)

ComboProductType.DisplayMember = "ProductType"
ComboProductType.DataSource = dt
 
Share this answer
 
Comments
Member 14649324 19-Oct-21 12:28pm    
@Richard Deeming Thank you so much it work perfect

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900