Creating a DataTable - madcodemonkey/ClassToDataTable GitHub Wiki
To create a DataTable from a List of T, there are 7 basic steps
- Add the ClassToDataTable NuGet package to your project
- Create a class
- Optional: Attribute the class with the [ClassToDataTable] attribute if the DataTable column name should be different from the class property name. You can also control the order the columns are written by using the ONE based Order property.
- Instantiate the ClassToDataTableService class
- Add ClassToDataTable namespace to your using statements.
- Use the AddRow or AddRows methods to add class instances as rows to your data table.
- Use the Table property on the ClassToDataTableService class to gain access to your DataTable
Examples
- Simple Example 1 - In this simple example to show basic usage
- SQL Bulk Copy Example - Shows how the ClassToDataTable can be used with Microsoft's SQLBulkCopy
Advanced Topics
- Type Converters - Convert C# types into new types to stuff into the DataTable.
Helpful links
- DataTable supported data types - See Remarks section for the list of supported .NET data types.