gpt4 book ai didi

c# - 如何找到违规列?无法从字符串转换为 int32

转载 作者:行者123 更新时间:2023-11-30 16:33:38 27 4
gpt4 key购买 nike

我正在使用 SqlBulkCopy。所以我制作了一个数据表并指定了它的列,然后将行添加到数据表,然后尝试插入它。

System.InvalidOperationException was unhandled by user code Message=The given value of type String from the data source cannot be converted to type int of the specified target

不过我一直收到这个错误。问题是我有 3 个 int 列,但我不知道是哪一个。

我什至把它的类型放在每个 int 列上。

 datatable.Columns.Add("Id", typeof(int));

似乎还是有问题。那么它会在堆栈跟踪或 int 异常中的什么地方说出它死于的实际列?

最佳答案

查看 Bruce Dunwiddie 的优秀 ValidatingDataReader类(class)。当您遇到此类映射问题时,它会在异常消息中提供非常好的信息。

关于c# - 如何找到违规列?无法从字符串转换为 int32,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2978068/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com