Hi Guys,

I am in situation.. where I need to Convert List of Class objects to DataTable.
for example :

- Class Product
- ProductId,ProductName,Description,Price are the Product class's get/set properties.
- I got List<Products> - this need to DataTable

any help would be great...

Thank you

Looked at some of the links in this thread, and am surprised on how complicated some of these examples tend to be.

I use serialization and deserialization with a Binaryformater to store and retrieve class instances between an SQL database and a Windows form.

If you need more information on the subject, I can refer you to a wonderful book that explains it in detail, or I can supply you with a code snippet to get you started with this technique.

// Jerry

Hi Jerry,

Thank you, Please provide me the more info.. about the book and where can I get that...

http://www.amazon.com/Programming-NET-Components-Juval-Lowy/dp/0596102070/ref=sr_1_1?ie=UTF8&s=books&qid=1240018238&sr=1-1

The O'Reilly book by Juval Lowy named Programming .NET Components is a good resource.

The Serialization of a class to a byte array that can then be placed into a database record, then deserialized back again into your application at a later time is simple.
I use this technique a lot, as I have a Plugin framework that loads many DLLs as modules, forms, etc. One of the places where streaming the class comes in handy is capturing the Icon, a bunch of properties like the menu item the plugin will be loaded under, security settings and the like. The data is read in from the database, and the menus and buttons arranged according to the classes that are deserialized.

Another example is a painting program that has many layers. Rather than storing each layer in a sub-table, I just serialize the entire class collection of component properties, and place that in the database as a single record. When the user wants to see this artwork, I pull it from the database, and deserialize it, dynamically create all of the objects in the correct Z order, and render the artwork to the user (extremely fast and efficient).

// Jerry

This article has been dead for over six months. Start a new discussion instead.