how to SqlBulkCopy using different column between excel and dabase table

on Mar 16, 2016 04:24 AM

Can anyone tell me how to add data using excel data with 3 columns into database table that has 9 columns.

I'm using this tutorial to bulk my data.

FYI: I'm totally newbie

Thanks & Regards

Download FREE API for Word, Excel and PDF in ASP.Net: Download
on Mar 16, 2016 04:25 AM


You need to map the Column name link below as Given in article

sqlBulkCopy.ColumnMappings.Add("Id", "PersonId")
sqlBulkCopy.ColumnMappings.Add("Name", "Name")
sqlBulkCopy.ColumnMappings.Add("Salary", "Salary")

I hope this will help you out.

on Mar 16, 2016 06:59 AM

I did that, but when I debug the code it shows error something like the destination table and source table are not match up.


FYI: My excel columns are 3 and my sql table columns are 8(so I think it's because of that)

on Mar 17, 2016 04:06 AM
on Mar 17, 2016 04:11 AM


Make sure that all other column must be nullable for which you are not passing value or they must have default constraint

I hope this will help you out.



on Mar 17, 2016 07:22 AM

I found the issue, it seems that I misstype the column name.


@Shshikant: thanks for your attantion and help :)

on Mar 17, 2016 07:33 AM
Instead of saying thanks mark the reply or replies(if multiple) that helped as Answer.