Search code examples
c#datetimefilehelpers

How to skip over bad records


I am using File Helpers 2.9.9 and I am wondering how do I get it skip over bad records instead of it just crashing?

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

I am also having trouble with the DateTime.I can't see why it can't convert "12/22/2011" using the formats I have set.

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'

Solution

  • 1) [EDIT] - I was wrong, you can set engine.ErrorManager.ErrorMode to SaveAndContinue - see the examples @ http://www.filehelpers.com/example_errorhandling.html

    2) based on the single quotes containing a string with double-quotes, I would say the problem is that you need to provide the FieldQuoted attribute - see http://www.filehelpers.com/attributes.html