-
May 1st, 2013, 08:08 PM
#1
Thread Starter
Member
Selecting a single column from database table and populate it in a listbox
i have a code here that i want to show the data from the database of a certain column,
HOWEVER THE LISTBOX SHOWS:
System.Data.DataRow
System.Data.DataRow
System.Data.DataRow
System.Data.DataRow
System.Data.DataRow
instead of the data in the database.
this is my current code:
Code:
Dim conn As SqlCeConnection = Nothing
Try
conn = New SqlCeConnection("Data Source=" & userSpecifiedPath)
conn.Open()
Dim cmd As SqlCeCommand = conn.CreateCommand()
Dim dAdp As SqlCeDataAdapter = New SqlCeDataAdapter()
Dim ds As New DataSet
cmd.CommandText = String.Format("SELECT STATUS FROM DELIVERY")
dAdp.SelectCommand = cmd
cmd.ExecuteReader()
dAdp.Fill(ds)
ListBox2.DataSource = ds.Tables(0)
cmd.ExecuteNonQuery()
Catch ex As Exception
Finally
conn.Close()
End Try
ALREADY SOLVED
Last edited by bea19_ventura; May 1st, 2013 at 08:12 PM.
-
May 1st, 2013, 08:14 PM
#2
Re: Selecting a single column from database table and populate it in a listbox
You need to set the DisplayMember of the ListBox to tell it which column or property of the bound list to display. If you don't, it simply calls ToString on each item to get a text value to display. While it's not essential, it should be set BEFORE setting the DataSource.
By the way, your code is a bit all over the place. You are actually executing your query three times. Get rid of the ExecuteReader and ExecuteNonQuery calls. You might like to follow the CodeBank link in my signature and check out my Retrieving & Saving Data thread to learn when to use which options.
-
May 1st, 2013, 08:25 PM
#3
Thread Starter
Member
Re: Selecting a single column from database table and populate it in a listbox
i have in my listbox data with spaces. i want to separate the data before the space and the data after the space. (ex. abc 123) how can i separate the data and put the other in another listbox.
by the way thanks for the advice in #2.
-
May 1st, 2013, 09:10 PM
#4
Re: Selecting a single column from database table and populate it in a listbox
The topic you raised in your original post has been resolved. Please mark this thread as Resolved to indicate that and start a new thread for a new topic.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|