lundi 24 août 2015

SQLite 'string was not recognized as valid DateTime'

I am attempted to retrieve DateTime information from each of my rows in my SQLite database, but I am receiving the error 'string was not recognized as valid DateTime' and I don't have much idea why this is happening so any help will be greatly appreciated.

foreach (DataRow row in table.Rows)
{
    string gameName = row["GameName"].ToString();
    //DateTime releaseTime = (DateTime)row["ReleaseTime"];
    DateTime releaseTimeGB = DateTime.ParseExact("dd/mm/yyyy", row["ReleaseTime"].ToString(), new CultureInfo("en-GB"));
    gameInfo.Add(new GameInfo() { Name = gameName, ReleaseTime = releaseTimeGB});
}

Now the commented out section in the above code does work but it retrieves the DateTime information in a format that I don't want, so the error is coming from the ParseExact() method. After looking around online it's pretty apparent that the exact source of the error is from calling the ToString() method on row["ReleaseTime"], but I am unsure on how to correct this as this is my first time using SQLite.

Aucun commentaire:

Enregistrer un commentaire