✅ Convert null datetime error in sqlite myReader
anyone know how to fix an issue with pulling a null datetime from sqlite into myReader? it keeps throwing an error that '' is an invalid string. I even put in a case like (myReader["columnName"].ToString() != null) ? Convert.ToDateTime(myReader["columnName"].ToString()) : Convert.ToDateTime(null) and that does not work
11 Replies
it won't necessarily fix your error, but you should use
DateTime.Parse
instead of Convert.ToDateTime
most of the conversion methods in Convert
are obsolete
besides that, debug your code to check the string you're getting before trying to parse itHow about: if (myReader["columnName"] != DBNull.Value)
potentially, i'm not too familiar with raw ADO.NET
it doesn't like the DateTime.Parse either... keeps telling me that '' is an invalid string
correct, if the string is empty then it's not a valid
DateTime
stringthe DBNull.Value did work though... not sure why that would work vs just null
probably an ADO.NET specific thing
is there a reason you aren't using an ORM?
ORM?
object relational mapper, basically a library that can handle anything from basic data mapping to managing your whole DB and generating queries from C# code
the former would be something like Dapper, latter like EF Core
I am moving to EFCore but wanted to get the basic program working before I change it all over because then I can change it by class without ruining the whole thing