in

System.Data.SQLite

An open source ADO.NET provider for the SQLite database engine

DataAdapter FIll errors out when DATE column contains a NULL

Last post 02-09-2010 10:07 PM by alex21. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 02-09-2010 9:26 AM

    DataAdapter FIll errors out when DATE column contains a NULL

    I have a sqlite table that has a DATE column (I am 100% positive that all of the values are valid).  When I try to do a .Fill into a data table, I get the exception "String was not recognized as a valid DateTime."

       at System.DateTimeParse.ParseExactMultiple(String s, String[ formats, DateTimeFormatInfo dtfi, DateTimeStyles style)
       at System.DateTime.ParseExact(String s, String[ formats, IFormatProvider provider, DateTimeStyles style)
       at System.Data.SQLite.SQLiteConvert.ToDateTime(String dateText)
       at System.Data.SQLite.SQLite3.GetDateTime(SQLiteStatement stmt, Int32 index)
       at System.Data.SQLite.SQLite3.GetValue(SQLiteStatement stmt, Int32 index, SQLiteType typ)
       at System.Data.SQLite.SQLiteDataReader.GetValue(Int32 i)
       at System.Data.SQLite.SQLiteDataReader.GetValues(Object[ values)

    I would expect this to not error out and the result to be DBNull in that particular row/column, am I mistaken?

    I am using VS2010 B2 and am using the build that for this version of the IDE.

    [UPDATE]  I did a little more digging and it turns out that if I am selecting 10 columns and the 3rd column is of type DATE, all columns from 3 to 10 come back with null values.

  • 02-09-2010 9:37 AM In reply to

    Re: DataAdapter FIll errors out when DATE column contains a NULL

    Make 100% sure they are all null and don't read "NULL" as a string.  if they are truly null, then it won't error out.

    Also the non-null date has to be properly formatted.

  • 02-09-2010 10:48 AM In reply to

    Re: DataAdapter FIll errors out when DATE column contains a NULL

    I am as clos to 100% sure as I can me -- if I use the native SQLite command line tool to display the data, they show up as null.

  • 02-09-2010 1:01 PM In reply to

    Re: DataAdapter FIll errors out when DATE column contains a NULL

    Ok, as I continue to research I think I have found the issue, but the behavior is still odd.

    The dates are actully formatted like this (valid ISO format, just apparently not valid for sqlite).

    MM-DD-YYYY (instead of YYYY-MM-DD)

    That said, why is it that not only does the date column come back as null but so does every column after the date (is it possible the code stops processing the results for all remaining columns when an error occurrs)?

    Now for the next question, anyone have any suggestions on how to fix the records since I cannot load them into ADO.NET and I cannot seem to find a way to parse them via SQL I am at a bit of a loss.

  • 02-09-2010 1:40 PM In reply to

    Re: DataAdapter FIll errors out when DATE column contains a NULL

    I am back to thinking this is a bug in the ADO.NET wrapper -- if I use the command line and some of the built in date/time functions everything works as expected.  If this is the case, shouldn't the ADO.NET wrappe work as well?

  • 02-09-2010 1:52 PM In reply to

    Re: DataAdapter FIll errors out when DATE column contains a NULL

    No, because the command-line doesn't care about strong types, and the ADO.NET provider does.  The ADO.NET provider expects an ISO8601-formatted datetime to be in a datetime field.  If you inserted your datetimes in a funky or region-specific format, then you need to reformat them.

    ISO8601 format is a good idea regardless... it's not possible to properly sort a datetime column in SQLite if you have it in MM-DD-YYYY format.

  • 02-09-2010 2:00 PM In reply to

    Re: DataAdapter FIll errors out when DATE column contains a NULL

    Not sure I agree, but that's ok :)

    So the question still stands, any suggestion on how to reformat all of the date strings I have?  I have over 200,000 records, so I cannot exactly drop the table and start over.

    It would be a nice feature to have the ADO.NET wrapper use the DateTime.Parse of the DateTime.ParseExact failes (as it would be able to handle this string without issue).

  • 02-09-2010 10:07 PM In reply to

    Re: DataAdapter FIll errors out when DATE column contains a NULL

     Ok so only way to avoid this is manually writing a method to reformat any dates to that format.

Page 1 of 1 (8 items)
Powered by Community Server (Commercial Edition), by Telligent Systems