Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Following is my datable column

Policy No	
Certificate/Asset Number	
Policy Start Date	
Policy End Date	
Loan Account No	
Customer Name	
Hypothecation	
Risk Location Address	
Suminsured	
Action


Following is my databse table column

policy_no
certificate_asset_number
policy_start_date
policy_end_date
loan_account_no
customer_name
hypothecation
risk_location_address
policy_suminsured
action


public UploadDetails UplodExcel(DataTable lst)
SqlBulkCopy objbulk = new SqlBulkCopy(con);
                objbulk.DestinationTableName = "abc_tbl";
                objbulk.ColumnMappings.Add("Policy No", "policy_no");
                objbulk.ColumnMappings.Add("Certificate/Asset Number", "certificate_asset_number");
                objbulk.ColumnMappings.Add("Policy Start Date", "policy_start_date");
                objbulk.ColumnMappings.Add("Policy End Date", "Policy End Date");
                objbulk.ColumnMappings.Add("Loan Account No", "loan_account_no");
                objbulk.ColumnMappings.Add("Customer Name", "customer_name");
                objbulk.ColumnMappings.Add("Hypothecation", "hypothecation");
                objbulk.ColumnMappings.Add("Risk Location Address", "risk_location_address");
                objbulk.ColumnMappings.Add("Suminsured", "policy_suminsured");
                objbulk.ColumnMappings.Add("Action", "action");
                objbulk.WriteToServer(lst);


above is code It's giving me following error

The given ColumnMapping does not match up with any column in the source or destination.


What I have tried:

i tried everything but not succeed please help me on this
Posted
Updated 17-Jun-23 8:47am
Comments
Richard MacCutchan 17-Jun-23 12:50pm    
Which line causes the error?
Akshay malvankar 17-Jun-23 13:07pm    
objbulk.WriteToServer(lst);

See this article Space in the column’s name[^]
You might need to put the column name in brackets like below;

SQL
use DemoDatabase
go
/*Query with square bracket*/
select  [country code], [country name]
from tblCountries
Go
/*Query with double quotes*/
select  "country code", "country name"
from tblCountries
Go


objbulk.ColumnMappings.Add("[Policy No]", "policy_no");
 
Share this answer
 
v2
Look at your code:
C#
objbulk.ColumnMappings.Add("Policy End Date", "Policy End Date");
Then chck the tables: policy_end_date should be in that one:
C#
objbulk.ColumnMappings.Add("Policy End Date", "policy_end_date");
 
Share this answer
 
Comments
Akshay malvankar 18-Jun-23 1:33am    
Thank you
OriginalGriff 18-Jun-23 2:23am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900