相关疑难解决方法(0)

SqlBulkCopy - 数据源中String类型的给定值无法转换为指定目标列的类型money

我在尝试从DataTable执行SqlBulkCopy时遇到此异常.

Error Message: The given value of type String from the data source cannot be converted to type money of the specified target column.
Target Site: System.Object ConvertValue(System.Object, System.Data.SqlClient._SqlMetaData, Boolean, Boolean ByRef, Boolean ByRef)
Run Code Online (Sandbox Code Playgroud)

我理解错误说的是什么,但我怎样才能获得更多信息,例如行/字段正在发生?数据表由第三方填充,最多可包含200列和最多10k行.返回的列取决于发送给第三方的请求.所有的数据表列是字符串类型.我的数据库中的列不是所有varchar,因此,在执行插入之前,我使用以下代码格式化数据表值(删除非重要代码):

//--- create lists to hold the special data type columns
List<DataColumn> IntColumns = new List<DataColumn>();
List<DataColumn> DecimalColumns = new List<DataColumn>();
List<DataColumn> BoolColumns = new List<DataColumn>();
List<DataColumn> DateColumns = new List<DataColumn>();

foreach (DataColumn Column in dtData.Columns)
{
    //--- find the field map that tells …
Run Code Online (Sandbox Code Playgroud)

c# datatable sqlbulkcopy

45
推荐指数
7
解决办法
10万
查看次数

标签 统计

c# ×1

datatable ×1

sqlbulkcopy ×1