无法将DateTime列的值指定为String

时间:2016-09-22 12:29:29

标签: c# .net asp.net-mvc-3 datatable sqlbulkcopy

面对错误:

  

使用DateTime

将数据插入数据库时​​,无法将数据源中String类型的给定值转换为指定目标列的SqlBulkCopy类型

仅在一台服务器中,对于其他服务器以及在我的开发环境中,一切正常。

   using (SqlBulkCopy sbc = new SqlBulkCopy(DbSqlConn))
                       {
                           DbSqlConn.Open();

                           // inserting data into table IT000
                           sbc.DestinationTableName = strschema + StoredProcedureNames.UPLOADTABLEGENERICHRIT000;

                           // Number of records to be processed in one go
                           sbc.BatchSize = tblUploadData.Rows.Count;


                           sbc.ColumnMappings.Add("txtEmployeeNo", "txtEmployeeNo");
                           sbc.ColumnMappings.Add("txtCompany", "txtCompany");
                           sbc.ColumnMappings.Add("txtEmpTypeCode", "txtEmpTypeCode");
                           sbc.ColumnMappings.Add("intProcessId", "intProcessId");
                           sbc.ColumnMappings.Add("txtBatchID", "txtBatchID");
                           sbc.ColumnMappings.Add("intUploadType", "intUploadType");

                           sbc.ColumnMappings.Add("intSubTypeSAP", "intSubTypeSAP");
                           sbc.ColumnMappings.Add("txtReasonSAPCode", "txtReasonCode");
                           sbc.ColumnMappings.Add("txtReasonSAPCode", "txtReasonSAPCode");

                          // sbc.ColumnMappings.Add("txtEmployeeSubGroup", "txtEmployeeSubGroup");

                           sbc.ColumnMappings.Add("dtStartDate", "dtStartDate");
                           sbc.ColumnMappings.Add("txtCreatedBy", "txtCreatedBy");
                           sbc.ColumnMappings.Add("dtCreatedDate", "dtCreatedDate");
                           sbc.ColumnMappings.Add("dtLastModifiedDate", "dtLastModifiedDate");
                           sbc.ColumnMappings.Add("txtLastModifiedBy", "txtLastModifiedBy");

                           sbc.ColumnMappings.Add("flgInfoTypeEvent", "flgInfoTypeEvent");
                           sbc.ColumnMappings.Add("txtReferenceKey", "txtReferenceKey");
                           sbc.ColumnMappings.Add("flgstatus", "flgstatus");
                           sbc.ColumnMappings.Add("txtRemarks", "txtRemarks");
                           sbc.ColumnMappings.Add("flgModified", "flgModified");
                           sbc.WriteToServer(tblUploadData);
                           intRes = 1;
                           sbc.Close();
                           DbSqlConn.Close();

                       }

0 个答案:

没有答案