Reputation: 5547
Why isn't this cast working? table.Columns.Cast<DataColumn>()
using (SqlBulkCopy bcp = new SqlBulkCopy(conn))
{
if (conn.State != ConnectionState.Open)
conn.Open();
bcp.DestinationTableName = destinationTable;
//map the columns in the datatable to the sql table
table.Columns.Cast<DataColumn>().ToList().ForEach(c => bcp.ColumnMappings.Add(c.ColumnName, c.ColumnName));
}
I thought I was going crazy, so I tried a test table... Same thing...
This is the error:
Error 1 'System.Data.DataColumnCollection' does not contain a definition for 'Cast' and the best extension method overload 'System.Data.EnumerableRowCollectionExtensions.Cast(System.Data.EnumerableRowCollection)' has some invalid arguments
Error 2 Instance argument: cannot convert from 'System.Data.DataColumnCollection' to 'System.Data.EnumerableRowCollection'
Upvotes: 4
Views: 3707