Reputation: 442
I have a dataset and it has a InsertQuery(String Name,String Surname,DateTime BDate)
Now I can wirte code like this,
_t.InsertQuer("Alper","AYDIN", null);
it can record data OK,
But I want to do like this,
_t.InsertQuery("Alper","AYDIN", dtBDate.IsEmpty==true?null:dtBDate.Value);
But when I Depoly it is give error like this;
Type of conditional expression cannot be determined because there is no implicit conversion between '' and 'System.DateTime'
How Can I set null ?
Upvotes: 0
Views: 313
Reputation: 1038730
Have you tried like this:
_t.InsertQuery("Alper","AYDIN", dtBDate);
where dtBDate
is Nullable<DateTime>
.
Also notice that you cannot pass null
if the InsertQuery
method takes DateTime
instead of Nullable<DateTime>
as last parameter.
Upvotes: 0
Reputation: 700252
The conditional operator needs to be able to return a single data type. Cast the null value to the null version of the other type:
_t.InsertQuery("Alper","AYDIN", dtBDate.IsEmpty?(DateTime?)null:dtBDate.Value);
Upvotes: 2