asp.net mvc c#sqkbulkcopy否为一个或多个必需参数指定的值

时间:2011-06-25 12:07:26

标签: c# asp.net asp.net-mvc-2

我遇到此错误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);
              }
           }
      }

1 个答案:

答案 0 :(得分:3)

比较目标表列列表与源表列列表相同。如果没有使用

映射源列和目标列详细信息
bulkCopy.ColumnMappings.Add("SourceCol", "DestinationCol1");
bulkCopy.ColumnMappings.Add("SourceCo2", "DestinationCol2");
bulkCopy.ColumnMappings.Add("SourceCo3", "DestinationCol3");