Reputation: 81
I'm using sqlite
and I'm trying to insert a DateTime
value, now happen in some case that the value's null
and I get this warning:
nullable object must have a value
the code that cause the fault is this:
command.Parameters.AddWithValue("Date", item.Start?.DateTime.Value.Date.ToString("yyyy-MM-dd"));
command
is the SQLiteCommand
and item
is a Google Calendar Event
(I'm using the Google Calendar API).
How you can see I've tried to fix declaring Start
as nullable with ?
but I got the same problem.
The value of Start
is this: {Google.Apis.Calendar.v3.Data.EventDateTime}
This is an image of the properties contained into .Start
:
How can I fix this?
Upvotes: 1
Views: 90
Reputation: 5735
In that case the object is C# null you should use DB null which is DBNull.Value
command.Parameters.AddWithValue("Date", (item.Start) ?? DBNull.Value);
Upvotes: 1