I'm trying to map the columns from a Datatable to an SQL database.Table, while mapping the columns. But i keep getting this error
"System.InvalidOperationException: 'The given ColumnName 'FobID' does not match up with any column in data source.'"
see the code im using bellow.
using(SqlBulkCopy sqlcopyTFobs = new SqlBulkCopy(destCNS))
{
sqlcopyTFobs.DestinationTableName = "[dbo].[TFobs]";
SqlBulkCopyColumnMapping mapFodID = new SqlBulkCopyColumnMapping("FobID", "FobID");
sqlcopyTFobs.ColumnMappings.Add(mapFodID);
sqlcopyTFobs.WriteToServer(dtTPositions);
}
If i copy all columns using the following code all data is copied. But i need to only copy certain columns.
using(SqlBulkCopy sqlcopyTFobs = new SqlBulkCopy(destCNS))
{
sqlcopyTFobs.DestinationTableName = "[dbo].[TFobs]";
sqlcopyTFobs.WriteToServer(dtTPositions);
}