tags:

views:

338

answers:

2

I have an MS Access database, which I have converted to an SQLite database. I have SubSonic setup and working, and I can pull data out of the database successfully into a WinForms app using ActiveRecord. All except for one table.

I get a FormatException, "String was not recognized as a valid DateTime". The format of the date column in the database is DD/MM/YYYY.

I'm not even trying to do anything too complicated:

 var allOrders = order.All();

 foreach (order o in allOrders)
 {
   listBox1.Items.Add(string.Format("{0} - {1}", o.OrderDate.HasValue ? o.OrderDate.Value.ToShortDateString() : string.Empty, o.Product));
 }

I'm not exactly sure why the problem is manifesting in the first place :(

+1  A: 

SQLite has "interesting" ways of formatting dates - you have to be very, very sure that you're getting back what you think you are because normally it's not DD/MM/YYYY - it's the opposite if I recall.

Rob Conery
Well, I can only assume something went wrong when I converted the MS Access .mdb to an SQLite db.As per @Roberto's suggestion:sqlite> select OrderDate from orders ...> limit 5;10240092000001024009200000102400920000010240092000001024009200000I've never seen Date/Time like that before. I'm thinking that the tool I used to convert the database is at fault here.
sgrassie
So I was kinda right about the database conversion tool I used mangling the date. http://code.google.com/p/mdb-sqlite/ is what I used - I hacked on the source, and modified it so that it converts the date column value to a string. After converting the database again, querying using sqlite3.exe gives a date in the OrderDate column as this: Fri Aug 22 00:00:00 BST 2008But, I'm still getting the FormatException, but now I think it's because the System.Data.SQLite.SQLiteDataReader can't see that string as a valid date because of the 'BST'.
sgrassie
A: 

I have the same issue. I'm getting dates back in "MM/DD/YYYY HH:MM:SS AM" format with sqlite3.exe, and I get the same exception. The odd thing is I'm getting it very early, using the DataReader class of that library:

var name = reader.GetName(index);

var val = reader.GetValue(index);

the exception throwns on the GetValue call with this stack trace:

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.SQLiteConvert.ToDateTime(IntPtr ptr, Int32 len) 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)

I'm testing using a Northwind database that has been converted to sqlite. I'm not sure how to go forward, this seems pretty fundamental!

moomi