Bytearray value instead of Datetime from sqlite table

Hello there,

My Application uses a SQLite Database. Every value from a database query result is accessible just fine, except datetime. In the Database it looks like a ordinary datetime, but if I try to access it, I get some byte array, that is difficult to assign to a DateTime in C#. I tried the following to convert the byte array, but I get a runtime error:

byte test_date = dataset_aschein.Arbeitsschein_Datum;
long test_date_long = BitConverter.ToInt64(test_date, 0);
aschein_date = DateTime.FromBinary(test_date_long);

The last line creates the follwing error:

fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
Unhandled exception in circuit 'sDHwYv30vFYKofFyWoT78ZchpmhQtrBiED4i-oBYbag'.
System.ArgumentException: The binary data must result in a DateTime with ticks between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks. (Parameter 'dateData')

What is wrong in my code and what would be the correct approach to get the datetime value from the sqlite database table? I tried it with a MSSQL database table, where a simple getvalue method sufficed.

Using a MSSQL Database the code that works is as follows

aschein_date = dataset_aschein.Arbeitsschein_Datum.GetValueOrDefault();

Hi @dignida,

Not sure how this is related to Radzen Blazor Studio, can you clarify?

I created the applictation in Radzen Blazor Studio. When the application was created I clicked on the "DATA" Button. In the "Create or Update a data source" window I selected "SQLite" and chose a local sqlite .db file. Then I created a new page, added some components, e.g. dropdown, datagrid and other text fields, that now I want to populate with data from the sqlite database. This works for most of the tables, that I selected with the scaffolding feature, except for one column, that contains DateTime values.

For instance, I select a database record and assign it to an object of type var:

arbeitsscheindaten = await ArbeitsscheinDBService.GetDboArbeitsscheins(new Radzen.Query { Filter = "i => i.Arbeitsschein_Nr == @0", FilterParameters = new object { ascheinID } });
var dataset_aschein = arbeitsscheindaten.First();

Now I can assign every value of that record to fields, that are of type string. This however does not work with values of type DateTime as I described above.

What is the type of the data item? Can you post the class generated by Radzen Blazor Studio, especially how the field with DateTime values is mapped? If it's byte[] you can change the generated code to DateTime and scaffold pages from the code:



RBS will automatically generate DatePickers:

Thank you for pointing me into the right direction. It was, just like you said, mapped to byte[ ], which now I changed to DateTime and it works now. Thank you!