c# - 如何跳过不良记录

标签 c# datetime filehelpers

我正在使用 File Helpers 2.9.9 我想知道如何让它跳过坏记录而不是崩溃?

object[] transactions = engine.ReadStream(textReader); // will crash if one record fails.

我也遇到了 DateTime 的问题。我不明白为什么它不能使用我设置的格式转换“12/22/2011”。

Error Converting '"12/22/2011"' to type: 'DateTime'.  does not match any of the given formats: 'MM/dd/yyyy', 'MM/d/yyyy', 'M/d/yyyy'
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: FileHelpers.ConvertException: Error Converting '"12/22/2011"' to type: 'DateTime'.  does not match any of the given formats: 'MM/dd/yyyy', 'MM/d/yyyy', 'M/d/yyyy'

最佳答案

1) [EDIT] - 我错了,您可以将 engine.ErrorManager.ErrorMode 设置为 SaveAndContinue - 请参阅示例 @ http://www.filehelpers.com/example_errorhandling.html

2) 基于包含带双引号的字符串的单引号,我会说问题是您需要提供 FieldQuoted 属性 - 请参阅 http://www.filehelpers.com/attributes.html

关于c# - 如何跳过不良记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8866512/

相关文章:

c# - 如何将刻度转换为分钟?

c# - 让 FileHelpers 2.0 处理带有多余逗号的 CSV 文件

c# - FileHelpers 库 CSV - 为什么总是从右侧的最后一列中删除一个字母?

c# - F# 中的 Func<T, TResult> 属性

c# - dotnet publish profile CLI 与 Visual Studio 的行为不同

c# - 带事务的 MySQL 表锁

c# - 使用 Entity Framework Core 进行全文搜索

javascript - 按日期过滤的正确方法是什么

python - 如何从Python中的整数列中获取前4位数字

asp.net - Filehelpers Excel 到 Oracle db