Wednesday, March 6, 2013

Convert object into DataTable C#

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

1 comment:

  1. To do that we must make use of reflection.
    This 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

    ReplyDelete