Results 1 to 2 of 2

Thread: [2005] Database Data in a listbox

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    [2005] Database Data in a listbox

    I made a very small database (im 50% sure i made it correctly) i wanted to show the database data in a listbox. I inserted the data by the data property value in the listbox properties and when i ran the application it just showed the file path of the database. It didnt show the data. How cna i fix this? Did i do something wrong...

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Database Data in a listbox

    Obviously you did something wrong but, given that you haven't shown us what you actually did, we can't see what is wrong with it. All we can do is give you general tips on what you should be doing, which you may or may not already be doing. If you give a clear and full description in the first place then you can get a clear and full solution right away.

    So, follow the Data Access link in my signature to see how to populate a DataTable with your data. Once you've got a DataTable you simply bind it to your ListBox:
    vb.net Code:
    1. myListBox.DisplayMember = "DisplayColumnName"
    2. myListBox.ValueMember = "IDColumnName"
    3. myListBox.DataSource = myDataTable
    The DisplayMember is the name of the column containing the data you want displayed. The ValueMember is generally the name of the column containing the record IDs. When you select an item in the ListBox you can get the corresponding ID from the control's SelectedValue property.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width