Results 1 to 7 of 7

Thread: populating listview from multiple tables

  1. #1
    jennann is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2012
    Location
    Davao City, Philippines
    Posts
    9
    Reputation
    0

    Smile populating listview from multiple tables

    Hi!..
    Is it possible to populate the listview from multiple tables?.
    I have a listview that I need to populate but in an order that is necessary.
    I would like to ask for an idea how..
    thank you!

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    12,859
    Reputation
    1623
    You can populate a ListView with whatever data you want. The ListView has no concept of where the data comes from. It simply displays whatever Strings you provide it, with no interest in where those Strings came from. If you want the data to come from multiple database tables then you need to retrieve data from multiple database tables. You haven't told us anything more about the relationship between the tables and how you want the data mapped to the ListView so we can;t tell you any more than that without guessing.

  3. #3
    jennann is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2012
    Location
    Davao City, Philippines
    Posts
    9
    Reputation
    0
    I'm sorry for not clarifying my question.
    I would like to cite an example, for instance I have tables named YearbookTable and CustomerTable.
    In YearbookTable, I have YearbookName, YearbookType, and DateReceived. While in CustomerTable, I have CustomerName, and Customer Address.
    In my Listview table, I would only populate it through these two tables, as mentioned, but with specific records only, such as, YearbookName, YearbookType, and CustomerName.
    I would like to ask if what method or how would I do this.
    Thank You!

  4. #4
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    12,859
    Reputation
    1623
    This really has nothing to do with the ListView then. You will be retrieving the data into a single DataTable and then looping through that to add one item to the ListView per row. You simply need to write the appropriate query to generate a single result set from multiple tables. As you haven't told us what the actual relationship is between the tables I cannot be specific, but it will be something like this:
    Code:
    SELECT p.Column1, c.Column2
    FROM Parent p INNER JOIN Child c
    ON p.ParentID = c.ParentID
    Parent.ParentID is a primary key and Child.ParentID is a foreign key, thus defining the relationship.

  5. #5
    jennann is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2012
    Location
    Davao City, Philippines
    Posts
    9
    Reputation
    0
    Ah, I see!.. Thank you!.. That's a new method/code for me.. I haven't encountered that(since I'm just learning vb.net).. I will give it a try.. Thank you again!

  6. #6
    jennann is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2012
    Location
    Davao City, Philippines
    Posts
    9
    Reputation
    0
    How do I put my code in a vb format?. I would like to show you my stupid code (hehe).

  7. #7
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    12,859
    Reputation
    1623
    Use the Advanced editor, click the little VB button and specify "vb.net" (without quotes) as the option. Just make sure that you post, as closely as you can tell, all the relevant code and no irrelevant code.

Bookmarks

Posting Permissions

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