-
Notifications
You must be signed in to change notification settings - Fork 0
Creating a DataTable
David Yates edited this page Apr 14, 2021
·
6 revisions
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
- 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
- Type Converters - Convert C# types into new types to stuff into the DataTable.
- DataTable supported data types - See Remarks section for the list of supported .NET data types.