Monday, August 29, 2005

Converting Class Array to DataTable

//Variable Declarations
private DataTable dtTemp;

private static void FillData(PropertyInfo[] properties, DataTable dt, Object o)
{
DataRow dr = dt.NewRow();
foreach(PropertyInfo pi in properties)
dr[pi.Name] = pi.GetValue(o, null);
dt.Rows.Add(dr);
}

//All the Properties for the class array are converted to columns. We can always add a
//condition to include required columns alone.
private static DataTable CreateDataTable(PropertyInfo[] properties)
{
DataTable dt = new DataTable();
DataColumn dc = null;
foreach(PropertyInfo pi in properties)
{
dc = new DataColumn();
dc.ColumnName = pi.Name;
dc.DataType = pi.PropertyType;

dt.Columns.Add(dc);
}
return dt;
}

public static DataTable ConvertToDataTable(Object[] array)
{
PropertyInfo[] properties = array.GetType().GetElementType().GetProperties();
DataTable dt = CreateDataTable(properties);
if (array.Length != 0)
{
foreach(object o in array)
FillData(properties, dt, o);
}
return dt;
}

//Call like this
//Convert the Class Object Array to DataTable
dtTemp = ConvertToDataTable(clsData);

Comments:
Valuable method for convert object array into datatable.Previously i used little bit complex method.Thanx a lot.
rgs chandima
 
Really Wonderful code. Helped me a lot
 
Thanks Kannan for taking the time to figure this out and post it online.
 
Es ist schade, dass ich mich jetzt nicht aussprechen kann - ist erzwungen, wegzugehen. Aber ich werde befreit werden - unbedingt werde ich schreiben dass ich denke. viagra kaufen cialis rezeptfrei [url=http//t7-isis.org]levitra bestellen[/url]
 
Wow, nice post,there are many person searching about that now they will find enough resources by your post.Thank you for sharing to us.Please one more post about that..
 
That is very good comment you shared.Thank you so much that for you shared those things with us.Im wishing you to carry on with ur achivments.All the best.
 
http://site.ru - [url=http://site.ru]site[/url] site
site
 
houston dating service http://loveepicentre.com/testimonials.php list of radioactive dating techniques
 
free ebook dictionary download http://audiobookscollection.co.uk/fr/Scattering-Theory/p192819/ download power of full engagement ebook [url=http://audiobookscollection.co.uk/de/Web-Development-With-Sas-by-Example/p106305/]ebook shannon butcher[/url] melissa de la cruz ebook
 
ebook heliodorus ethiopian http://audiobooksplanet.co.uk/Rediscovery-A-Novel-of-Darkover/p225939/ private placement memo ebook shareware trial [url=http://audiobooksplanet.co.uk/Omar-Al-Zabir/m94709/]certified protection professional ebook[/url] ebook dictionary free download
 
simetrix catena software http://buyoem.co.uk/product-10069/FXPak-Style-Volume-3-for-Adobe-Photoshop-CS2 adobe firefly software [url=http://buyoem.co.uk/product-37381/Clean-Memxp-9-2-Portable]serona dental software[/url] computer midi sequencer software
[url=http://buyoem.co.uk/product-37356/UltraEdit-32-Professional-13-2]UltraEdit 32 Professional 13.2 - Software Store[/url] parameter diagram and software
[url=http://buyoem.co.uk/fr/product-37386/DVD-Lab-Pro-2-5][img]http://buyoem.co.uk/image/7.gif[/img][/url]
 
overdubbing recording software http://buyoem.co.uk/it/product-36236/Zards-Software-Startup-Defender-2-8 origin mapping software [url=http://buyoem.co.uk/product-35525/Xilisoft-Audio-Maker-6-2-Multilanguage]swing chords software[/url] outsourcing software solution india
[url=http://buyoem.co.uk/it/category-100-106/Software-di-server]Software di server - Software Store[/url] grant proposal writing software
[url=http://buyoem.co.uk/product-37382/Clean-MemXP-9-4][img]http://buyoem.co.uk/image/2.gif[/img][/url]
 
gps software voice http://buysoftwareonline.co.uk/es/category-7/Programaci-n-y-elaboraci-n?page=19 yadda yadda yadda software [url=http://buysoftwareonline.co.uk/product-37358/USB-Trace-2-0]simply accounting training software[/url] parental monitoring software free trial version
[url=http://buysoftwareonline.co.uk/fr/contact]Contactez-nous - Cheap Legal OEM Software, Software Sale, Download OEM[/url] best data recovery software and utilites
[url=http://buysoftwareonline.co.uk/es/category-100-101/Sistemas-operacionales?page=2][img]http://buyoem.co.uk/image/5.gif[/img][/url]
 
[url=http://certifiedpharmacy.co.uk/products/omnicef.htm][img]http://onlinemedistore.com/12.jpg[/img][/url]
chattanooga pharmacy technician http://certifiedpharmacy.co.uk/products/abana.htm internet pharmacy bulletin boiards [url=http://certifiedpharmacy.co.uk/catalogue/x.htm]pharmacy phone[/url]
katwijk pharmacy http://certifiedpharmacy.co.uk/categories/anti-herpes.htm inhouse pharmacy sumatriptan imigran imitrex tablets [url=http://certifiedpharmacy.co.uk/products/tretinoin-cream-0-05-.htm]tretinoin cream 0 05 [/url]
pennsylvania pharmacy leglisltion http://certifiedpharmacy.co.uk/products/evista.htm document control procedurein community pharmacy [url=http://certifiedpharmacy.co.uk/categories/weight-loss.htm]cals pharmacy snowbords[/url]
pharmacy degree online http://certifiedpharmacy.co.uk/products/differin.htm pharmacy requirements [url=http://certifiedpharmacy.co.uk/products/diamox.htm]diamox[/url]
 
[url=http://certifiedpharmacy.co.uk/categories/stop-smoking.htm][img]http://onlinemedistore.com/1.jpg[/img][/url]
cvs pharmacy chester nj http://certifiedpharmacy.co.uk/products/terramycin.htm pharmacy technician training online [url=http://certifiedpharmacy.co.uk/products/zyvox.htm]what exam to take for pharmacy technician[/url]
caremark specialty pharmacy ma http://certifiedpharmacy.co.uk/products/aceon.htm jefferson pharmacy philadelphia [url=http://certifiedpharmacy.co.uk/products/arava.htm]arava[/url]
advanced compounding pharmacy http://certifiedpharmacy.co.uk/products/oxytrol.htm inventory management pharmacy [url=http://certifiedpharmacy.co.uk/catalogue/e.htm]denmark pharmacy history[/url]
pharmacy concerns http://certifiedpharmacy.co.uk/products/purim.htm myriad pharmacy [url=http://certifiedpharmacy.co.uk/products/glucophage.htm]glucophage[/url]
 
[url=http://englandpharmacy.co.uk/products/glucotrol-xl.htm][img]http://onlinemedistore.com/9.jpg[/img][/url]
does pa regulate internet pharmacy http://englandpharmacy.co.uk/products/glucotrol-xl.htm walmart pharmacy in erie pa [url=http://englandpharmacy.co.uk/products/actonel.htm]document control procedurein community pharmacy[/url]
maine pharmacy law pseudoephedrine http://englandpharmacy.co.uk/catalogue/s.htm wegmans pharmacy fairport ny [url=http://englandpharmacy.co.uk/products/proscar.htm]proscar[/url]
surgical supplies pharmacy eighth avenue new york http://englandpharmacy.co.uk/products/premarin.htm pharmacy continue education [url=http://englandpharmacy.co.uk/products/lioresal.htm]how to become certified for pharmacy tech[/url]
lipitor online pharmacy http://englandpharmacy.co.uk/products/coreg.htm south dakota state university pharmacy visit [url=http://englandpharmacy.co.uk/products/gift-kamagra-jelly.htm]gift kamagra jelly[/url]
 
dating blueridge guitar [url=http://freeinternetdating.info/romantic/romantic-call]romantic call[/url] glass door knob dating
liberal dating http://freeinternetdating.info/brides/princess-warrior-brides-from-another-planet jopline dating
thinkers and feelers dating [url=http://freeinternetdating.info/socialnetwork/browning-logo-myspace-layouts]cougar women dating[/url] d s dating sites
 
dating websites for sale http://loveepicentre.com/taketour/ american girls for dating
torrent double your dating [url=http://loveepicentre.com/articles/]forensic science carbon dating autopsy[/url] porn tube wives dating
adult dating swinging oregon [url=http://loveepicentre.com/advice/]sex dating in romeoville illinois[/url] totally free no payment dating sight [url=http://loveepicentre.com/user/Akron/]Akron[/url] dating sims new websites
 
Nice Post Love Reading Its

generic Viagra 100mg

kamagra 100mg
 
Post a Comment

This page is powered by Blogger. Isn't yours?