我遇到此错误No Value given for one or more required parameter
可能是错误的原因。这是代码
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);
}
}
}
答案 0 :(得分:3)
比较目标表列列表与源表列列表相同。如果没有使用
映射源列和目标列详细信息bulkCopy.ColumnMappings.Add("SourceCol", "DestinationCol1");
bulkCopy.ColumnMappings.Add("SourceCo2", "DestinationCol2");
bulkCopy.ColumnMappings.Add("SourceCo3", "DestinationCol3");