0
Hello, I am trying to update data from a row of a db sqlite, however I am having problem in a date field.
I enter data in the Registered field with the following code, where Tb_data_registered is a Datetimepicker:
command.Parameters.Add("@Registrado", DbType.Date).Value = TB_Data_Cadastro.Value.Date;
After entering and consulting the database is saved this way: 2020-12-03 00:00:00
However, when changing any row with the following command the date type changes:
SQLiteCommand command = new SQLiteCommand("UPDATE Produtos_TB SET Registrado = '" + TB_Data_Cadastro.Value.Date + "' WHERE ID = '" + id + "'");
And consulting the database in the same field become: 3.12.20 00:00:00
So from when the date is in this second format (3.12.20) any query or something you do in db returns me this error:
System.FormatException: 'Cadeia de caracteres não foi reconhecida como DateTime válido.'
I did a search and found that Sqlite uses a date type that is yyyy-MM-dd HH:mm:ss, based on that I tried to format the date for the line to be updated this way, but without success. When registering I saw that maybe a conversion of System.Datetime to Dbtype.Date, but I could not apply something similar in my code.
if you have the typed parameter
@Registrado
, why in theUPDATE
you are trying to concatenate directly the value of Datepicker?– Leandro Angelo
Ahhh is Sqlite, has to be string even
– Leandro Angelo
Yes, I still researched other ways to do the
UPDATE
but it is in this way, I think the problem is that it is inserted the date format that is configured on the computer and not in the format of Sqlite. I’ll keep trying to figure it out.– doc_.