how to add column mapping in sqlbulkcopy in c# where column names contains White Space

.net sql sqlbulkcopy

Question

using (SqlBulkCopy sc = new SqlBulkCopy(conn))
{
    sc.DestinationTableName = destination;

    sc.ColumnMappings.Add("ID","ID #");
    sc.ColumnMappings.Add("Amount","Amount in USD");

    sc.WriteToServer(datatable);
}

I am getting error that column dose not match in given columnmapping

Thanks in Advance.

Popular Answer

found solution need to add Square brackets around the fields only where the White space involved in column name



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why