I successfully pulled the CSV file into the following class:
[DelimitedRecord(",")] [IgnoreFirst(1)] // ignores first line of file, since it a header public class Employee { public string EmployeeId; public string FirstName; public string LastName; // etc. }
I need to create a DataTable based on this class in order to use SqlBulkCopy. I found some examples, but the following method does not work for me:
private static DataTable createEmptyDataTable(Type myType) { DataTable dt = new DataTable(); foreach (PropertyInfo info in myType.GetProperties()) { dt.Columns.Add(new DataColumn(info.Name, info.PropertyType)); } return dt; }
The problem is myType.GetProperties (). This is not an error, but returns nothing. The PropertyInfo array that it should return is empty. Was at this time and can not understand the problem ...
EDIT: I also used this option without success:
private static DataTable createEmptyDataTable(Type myType) { DataTable dt = new DataTable(); PropertyInfo[] infoArray = myType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static); foreach (PropertyInfo info in infoArray) { dt.Columns.Add(new DataColumn(info.Name, info.PropertyType)); } return dt; }
source share