How to add new column in SQL Server using SqlBulkCopy which is not present in Excel using asp.net

asp.net c#-4.0 sqlbulkcopy sql-server

Question

Using ASP.NET, I'm developing an application that will upload data from Excel to SQL Server. I am aware of how to use Excel to upload data.SqlBulkCopy . However, I'm attempting to upload more data for the table column (addeddate , addedby ...etc.) that are absent from the Excel sheet.

I have the following error:

The given ColumnName '18-01-2016 17:24:07' does not match up with any column in data source.

1
0
1/18/2016 1:25:20 PM

Popular Answer

To enter constant values like addeddate, addedby, etc., try the following solution.

SELECT
    EXCEL_COL1, 
    EXCEL_COL2, 
    'newconstantvalue' as CustomCol 
FROM
    ExcelSheet1

Then

bulkCopy.ColumnMappings.Add("Table_COL3", "CustomCol");

Refer to the article for further information.

0
1/18/2016 1:06:03 PM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow