5

Is there a more "Light weight" type to Encapsulate table than DataTable?
I don't need so much properties, events and methods as the DataTable offers.
I need only the values; The columns caption and DataType will be also nice.

Is there such type built-in C#?

Update: I need it to create an Excel file from list

Community
  • 1
  • 1
gdoron
  • 147,333
  • 58
  • 291
  • 367
  • 1
    If you know the information you need to retrieve, you could just create a class and then use a data reader to populate the values? You would need a list of said class. One for each row returned. – seanzi Nov 28 '11 at 09:12
  • What functionality do you need? Why is datatable so heavy? – Preet Sangha Nov 28 '11 at 09:12
  • Just out of curiosity, why do you ever need that? Do you lack memory? – Hossein Nov 28 '11 at 09:14
  • DataTable is a disposable type and has some overhead. s. for example http://stackoverflow.com/questions/424598/what-is-the-memory-overhead-of-storing-data-in-a-net-datatable – Boas Enkler Nov 28 '11 at 09:15
  • I don't know the Excel API but wheres the link of DataTable and Excel ? BTW There are also Third Party APIs which can create ExcelDocuments Object based, even without having excel installied. for example infragistics See also: http://www.infragistics.com/dotnet/netadvantage/wpf/infragisticsexcel.aspx#Overview – Boas Enkler Nov 28 '11 at 09:21
  • Yeah I know those library and I using one of them, but still I need to format the data before creating the excel. – gdoron Nov 28 '11 at 09:25
  • I would love a light weight data table and have thought of writing one myself for a couple of years now. I love the convenience of datatables but have been hurt by memory and performance too many times. No one else has created this yet? – Kim Nov 12 '14 at 02:29

2 Answers2

2

I'm not sure wether it meets your requirements, but i would recommend using your own custom entites. Perhaps with some kind of DSL Language.

Or have a look at the EntityFramework, it can generate classes from existing dbms.

IMO DataTable are an old not anymore state of the art element.

So the key question is what do you want to achieve. What are your requirements?

And can you use own entities to achieve this ?

Boas Enkler
  • 12,264
  • 16
  • 69
  • 143
1

The lightest-weight equivalent to a DataTable would be a 2-dimensional array. Bit puzzled why a DataTable is too heavy? Is this embedded programming you are doing? I'd stick with a datatable anyway. It's efficient and the extra functionality may come in useful down the line if the specs change.

Gavin Ward
  • 1,022
  • 8
  • 12