Results 1 to 3 of 3

Thread: .mdf Database and ListView

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2012
    Posts
    28

    .mdf Database and ListView

    How would one iterate through a collection of items in a column from a table in a database. Then display that in a listView.

    I know how to adequately use a ListView object. However, I don' know how to iterate through items in a table from a database. How would I go about doing this?
    Last edited by Anthony123; May 6th, 2013 at 07:07 PM.

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

    Re: .mdf Database and ListView

    A DataTable has rows and columns and to traverse data with rows and columns you pretty much always use nested loops. The outer loop would go through the rows of the table and the inner loop would go through the columns of the current row. Given that a ListView with its View set to Details also has rows and columns, there's a very close correspondence between the two.

    That said, far too many beginners choose to make their lives difficult by using a ListView to display data from a database when they should not. More often than not you should be using a DataGridView or some other genuine grid control, which the ListView is not. If you use a DataGridView then you can take advantage of data-binding, so there's no need for any code to transfer the data from the table to the grid and back again.
    Last edited by jmcilhinney; May 6th, 2013 at 07:45 PM.
    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

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2012
    Posts
    28

    Re: .mdf Database and ListView

    Very helpful advice, thank you for your prompt and informative response.

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