Set constant value to some columns in SqlBulkCopy

c# csv mapping sqlbulkcopy

Question

I'm trying transfer data from "csv" file to SQL Database. Is it possible to map some fields by default vale which not exsits in "csv" file? Something like shown below: bulkCopy.ColumnMappings.Add("Destenition_column_name", "constant_value");

Thanks for advance!

Popular Answer

What about setting a default column BEFORE populating the DataTable?

var returnTable = new DataTable();
returnTable.Columns.Add("Constant_Column_Name").DefaultValue = "Constant_Value";

If you then add rows each row will always have the specified default value for this column without explicitly setting it.



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