|
-
Aug 18th, 2012, 06:27 PM
#4
Re: Best way to populate controls ona windows form
There is a flaw with the code. Right now, if the query returns more than one record, the While loop will load the first row into the controls, then immediately load the next row into the controls, thereby replacing the work you just did. The end result is that you will only show the final record returned by the datareader. If there will only be one row, then don't bother with the While loop. Instead, just call reader.Read one time and load the controls.
If you are returning mutlipe records, then the datatable would make sense, as you would be able to navigate forwards and backwards through it. If you are only loading a single row, as it appears you may be doing, then the datatable is probably not a good idea. The datatable won't be quite as fast as the datareader (though you won't see the difference). You still might want to use the datatable, though, if you will be changing any of the values and want to push those changes back to the DB, since a datatable can be used with a dataadapter to update the database quite easily.
Therefore, it kind of depends on what you eventual goal is for this data.
My usual boring signature: Nothing
 
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
|