Convert List of Class objects to Datatable

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2007
Posts: 34
Reputation: vizy is an unknown quantity at this point 
Solved Threads: 6
vizy's Avatar
vizy vizy is offline Offline
Light Poster

Convert List of Class objects to Datatable

 
0
  #1
Apr 10th, 2009
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
Njoy koding... >>>
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 38
Reputation: thacravedawg is an unknown quantity at this point 
Solved Threads: 0
thacravedawg thacravedawg is offline Offline
Light Poster

Re: Convert List of Class objects to Datatable

 
0
  #2
Apr 10th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 34
Reputation: vizy is an unknown quantity at this point 
Solved Threads: 6
vizy's Avatar
vizy vizy is offline Offline
Light Poster

Re: Convert List of Class objects to Datatable

 
0
  #3
Apr 10th, 2009
Thank You,

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

I particularly wanted as..
fnAllGetProducts().ToDatatable()
where fnAllGetProducts() returns the List<Products> objects
Njoy koding... >>>
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: Convert List of Class objects to Datatable

 
0
  #4
Apr 14th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 34
Reputation: vizy is an unknown quantity at this point 
Solved Threads: 6
vizy's Avatar
vizy vizy is offline Offline
Light Poster

Re: Convert List of Class objects to Datatable

 
0
  #5
Apr 17th, 2009
Hi Jerry,

Thank you, Please provide me the more info.. about the book and where can I get that...
Njoy koding... >>>
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: Convert List of Class objects to Datatable

 
0
  #6
Apr 17th, 2009
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC