|
-
May 6th, 2013, 06:55 PM
#1
Thread Starter
Junior Member
.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.
-
May 6th, 2013, 07:30 PM
#2
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.
-
May 6th, 2013, 07:39 PM
#3
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|