943,722 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 13740
  • C# RSS
Apr 10th, 2009
0

Convert List of Class objects to Datatable

Expand Post »
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
Reputation Points: 10
Solved Threads: 6
Light Poster
vizy is offline Offline
36 posts
since Dec 2007
Apr 10th, 2009
0

Re: Convert List of Class objects to Datatable

I think there is an easier way, but I cant figure it out right now. This could help you accomplish your goal.

http://www.codeproject.com/KB/cs/coreweb01.aspx
Reputation Points: 10
Solved Threads: 0
Light Poster
thacravedawg is offline Offline
38 posts
since Feb 2009
Apr 10th, 2009
0

Re: Convert List of Class objects to Datatable

Thank You,

I got something like this
http://amitpatriwala.wordpress.com/2...-to-datatable/

I particularly wanted as..
Quote ...
fnAllGetProducts().ToDatatable()
where fnAllGetProducts() returns the List<Products> objects
Reputation Points: 10
Solved Threads: 6
Light Poster
vizy is offline Offline
36 posts
since Dec 2007
Apr 14th, 2009
0

Re: Convert List of Class objects to Datatable

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
Reputation Points: 69
Solved Threads: 75
Posting Pro in Training
JerryShaw is offline Offline
465 posts
since Nov 2006
Apr 17th, 2009
0

Re: Convert List of Class objects to Datatable

Hi Jerry,

Thank you, Please provide me the more info.. about the book and where can I get that...
Reputation Points: 10
Solved Threads: 6
Light Poster
vizy is offline Offline
36 posts
since Dec 2007
Apr 17th, 2009
0

Re: Convert List of Class objects to Datatable

http://www.amazon.com/Programming-NE...0018238&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
Reputation Points: 69
Solved Threads: 75
Posting Pro in Training
JerryShaw is offline Offline
465 posts
since Nov 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: ASP.NET Authentication issue
Next Thread in C# Forum Timeline: Kuskal and Dijkstra





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC