Hi
In below code i am getting error - Cannot convert system.date.time? to system.date.time
List
Thanks
Hi
In below code i am getting error - Cannot convert system.date.time? to system.date.time
List
Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amit MohantyRank #112 · 20K reputationPosted Apr 7, 2023, 9:49 AM EDT
DateTime startDate = Result.StartDate ?? DateTime.MinValue; DateTime endDate = Result.EndDate ?? DateTime.MaxValue; List objResult = bALSessionDeliveryParticipant.GetSessionDeliveryParticipantList(startDate, endDate, mentor, group);Jignesh KumarRank #91 · 22.9K reputationPosted Apr 7, 2023, 9:55 AM EDT
Hi,
You are getting null value from database query response for datefield which is not nullable so it will throw error.
You can solve this problem in multiple ways,
You can add ? In your model as below
Public Datetime? StartDate {get; set;}
Tuhin PaulRank #7 · 71.9K reputationPosted Apr 7, 2023, 2:22 PM EDT
Instead of using the ternary operator to check for null values and set a default value, you can use the null-coalescing operator (??) to provide a default value if the StartDate or EndDate properties are null
Tuhin PaulRank #7 · 71.9K reputationPosted Apr 7, 2023, 2:23 PM EDT
Since the type of the objResult variable is already clear from the method name (GetSessionDeliveryParticipantList), you can use the var keyword to simplify the code
var objResult = bALSessionDeliveryParticipant.GetSessionDeliveryParticipantList(startDate, endDate, mentor, group);