Recently I got a requirement in a project to convert own type of object to DataTable. Here I am sharing my code with you.
Steps
1. Create datatable and give a name
2. Create Column Names
3. Create a Data Row
4. Add Data in to DataRow
5. Add DataRow to DataTable
Thats it...
Here some Extended Method to how to use this method
https://github.com/cbjpdev/DataTableX
To do that we must make use of reflection.
ReplyDeleteThis site explains how to do it, also has a pretty clear example
http://www.systemdeveloper.info/2014/06/convert-object-to-datatable-in-c.html