dzingoni:.
The problem lies in the actual data written in the db.
I have some records written correctly, some not.
if I execute the following SQL (always using SQL Administrator):
SELECT DateTime(LastUpdated), DateTime(ExpiresOn) from Objects
where the two fields LastUpdated and ExpiresOn are TIMESTAMP with CURRENT_TIMESTAMP as default, I get some records with the date, some empty.
It sounds like somebody updated the fields with strings in italian format. Are you using parametrized queries to do the updates or are you concatenating strings to build the CommandText?
If you concatenated the fields and used something like:
CommandText = "UPDATE ...." + SomeDate.ToString() + ' .... '
Then the filed is stored as a date formatted in the current regional settings.
If you used parametrized queries, perhaps you set incorrectly the parameter type.
dzingoni:
Is there a way to see the STRING that is actually recorded in the database file?
Yes, you can use DataReader.GetString() to see the stored strings. For example, (using the same table as before)
private void ShowStrings()
{
DataTable Table1 = new DataTable("Table1");
DataColumn IdCol = Table1.Columns.Add("Id", typeof(long));
DataColumn DateTimeFieldCol = Table1.Columns.Add("DateTimeField", typeof(string));
DataColumn StringFieldCol = Table1.Columns.Add("StringField", typeof(string));
using (SQLiteConnection cn = new SQLiteConnection("Data Source=TimestampTest.s3db"))
using (SQLiteCommand GetRecordsCmd = new SQLiteCommand("SELECT Id, DateTimeField, StringField FROM Table1", cn))
{
cn.Open();
using (SQLiteDataReader reader = GetRecordsCmd.ExecuteReader())
{
while (reader.Read())
{
DataRow row = Table1.NewRow();
row["Id"] = reader.GetInt64(0);
row["DateTimeField"] = reader.GetString(1);
row["StringField"] = reader.GetString(2);
Table1.Rows.Add(row);
}
}
Table1.AcceptChanges();
}
this.dataGridView1.DataSource = Table1;
}