i am having this error No Value given for one or more required parameter
what might be the reason for the error. here is the code
string excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + postdir + newFileNameOnServer + "; Extended Properties=Excel 8.0";
using (OleDbConnection connection =new OleDbConnection(excelConnectionString))
{
OleDbCommand command = new OleDbCommand("Select Month,Year,CountryofExport,CountryofOrigin,Hs_code,quantity,Unit,CustomValue,Type FROM [qryTradeFlowforWeb$]", connection);
connection.Open();
// Create DbDataReader to Data Worksheet
开发者_运维知识库 using (DbDataReader dr = command.ExecuteReader()) // the error coming here
{
string sqlConnectionString = ConfigurationManager.ConnectionStrings["KMFConnectionString"].ToString();
SqlConnection conn = new SqlConnection(sqlConnectionString);
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString))
{
bulkCopy.DestinationTableName = "ExcelData";
bulkCopy.WriteToServer(dr);
}
}
}
Compare the destinatin table clolum list is identical with the source table column list. if not map the source and destination colum details using
bulkCopy.ColumnMappings.Add("SourceCol", "DestinationCol1");
bulkCopy.ColumnMappings.Add("SourceCo2", "DestinationCol2");
bulkCopy.ColumnMappings.Add("SourceCo3", "DestinationCol3");
精彩评论