Click here to Skip to main content
15,886,857 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

With this i get the items from a database to a combobox .

But is it possible to show all items in a textbox seperate with /

SQL
<pre>  cmd = New SqlCeCommand("Select Id, Name FROM Product WHERE Name <>''", con)
        If con.State = ConnectionState.Closed Then con.Open()
        Dim sdr As SqlCeDataReader = cmd.ExecuteReader()
        While sdr.Read = True
            Product.Items.Add(sdr.Item("Name"))
        End While
        sdr.Close()


What I have tried:

When i select a textbox in the statement it is only showing 1 item

What do i change to get all items with / between the items in a textbox
Posted
Updated 9-Jan-19 19:36pm
Comments
BASSIES 9-Jan-19 16:59pm    
cmd = New SqlCeCommand("Select Id, Name FROM Product WHERE Name <>''", con)
If con.State = ConnectionState.Closed Then con.Open()
Dim sdr As SqlCeDataReader = cmd.ExecuteReader()
While sdr.Read = True
TextBox5.Text = (sdr.Item("Name"))
End While
sdr.Close()


This is only showing the last item
Mohibur Rashid 9-Jan-19 17:50pm    
I am trying to understand your issue here.
1. You don't know how to populate textbox
2. You don't know how to contact in VB.net
3. You don't know how to contact in SQL

Which one?

If I understand your question correctly, the smallest change could be to modify the loop to build a concatenated string. Something like

VB
...
        Dim sdr As SqlCeDataReader = cmd.ExecuteReader()
        Dim concatenatedResult As String
        concatenatedResult  = ""
        While sdr.Read = True
            If concatenatedResult <> "" Then
               concatenatedResult  = concatenatedResult & " / "
            End If
            concatenatedResult  = concatenatedResult + sdr.Item("Name").ToString()
        End While
        MyTextBox.Text = concatenatedResult 
...
 
Share this answer
 
Comments
BASSIES 10-Jan-19 3:03am    
Thanks Wendelius , just what i was looking for.
Wendelius 10-Jan-19 12:00pm    
You're welcome :)
Hi! Try using GROUP_CONCAT then replace the "," with "/".

Try applying this SQL code in your previous code:

SELECT REPLACE(GROUP_CONCAT(name),",","/") FROM product WHERE Name <>''"
 
Share this answer
 

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