DataTable vs. Collection in .Net

Posted by B Pete on Stack Overflow See other posts from Stack Overflow or by B Pete
Published on 2010-04-22T00:56:14Z Indexed on 2010/04/22 1:13 UTC
Read the original article Hit count: 333

Filed under:
|

I am writing a program that needs to read a set of records that describe the register map of a device I need to communicate with. Each record will have a handfull of fields that describe the properties of each register.

I don't really need to edit or modify the data in my VB or C# program, though I would like to be able to display the data on a grid. I would like to store the data in a CSV file, or perhaps an XML file. I need to enable users to edit the data off-line, preferably in excel.

I am considering using a DataTable or a Collection of "Register" objects (which I would define).

I prototyped a DataTable, and found I can read/write XML easily using the built in methods and I can easily bind to a DataGridView. I was not able to find a way to retreive info on a single register without using a query that returns a collection of rows, even though I defined a unique primaty key column. The syntax to get a value from a column is also complex, though I could be missing something on both counts.

I'm tempted to use a collection of "Register" objects that I can access via a unique key. It would be a little more coding up front, but seems like a cleaner solution overall. I should still be able to use LINQ to dataset to query subsets of registers when I need them, but would also be able to grab a single field using a the key value, something like this: Registers(keyValue).fieldName).

Which would be a cleaner approach to the problem?

Is there a way to read/write XML into a Collection without needing custom code?

Could this be accomplished using String for a key?

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about c#