Nullable object must have a value datetime

Kuzey Taylann Şengül

database

EmbarkDate       [] allowNulls checked
DisembarkDate    [] allowNulls checked

  update [dbo].[t_CrewContract] set EmbarkDate= null where cc_ID='AEDAEC31-6108-CE8F-97DF-114FD87A6257'
  update [dbo].[t_CrewContract] set DisembarkDate= null where cc_ID='AEDAEC31-6108-CE8F-97DF-114FD87A6257' 

c#

     public DateTime? EmbarkDate { get; set; }
     public DateTime? DisembarkDate{ get; set; }

ContractItems.Add(new ContractItem
                    {
   EmbarkDate = item.cc_EmbarkDate.HasValue != null ? item.cc_EmbarkDate.Value : item.cc_EmbarkDate = null,

   DisembarkDate = item.cc_DisembarkDate.HasValue != null ? item.cc_DisembarkDate.Value     : item.cc_DisembarkDate = null,

});

if(activeContract.EmbarkDate == null)
{
  //...codes
}

error : Nullable object must have a value What's the problem thank you

Darren Kopp
EmbarkDate = item.cc_EmbarkDate.HasValue != null 
    ? item.cc_EmbarkDate.Value : item.cc_EmbarkDate = null,

DisembarkDate = item.cc_DisembarkDate.HasValue != null
    ? item.cc_DisembarkDate.Value : item.cc_DisembarkDate = null

The problem here is you are comparing HasValue to null, which will always be false since it's a boolean.

You want to just have as below and same DisembarkDate.

EmbarkDate = item.cc_EmbarkDate.HasValue ? (DateTime?)item.cc_EmbarkDate.Value : item.cc_EmbarkDate = null

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

best method to solve Nullable object must have a value in datetime

From Dev

Linq: Nullable Object must have Value

From Dev

Decimal? - Nullable object must have a value

From Dev

"Nullable object must have a value" when Where uses a method?

From Dev

Nullable object must have a value. VB.NET

From Dev

Anonymous Type "Nullable object must have a value" Error

From Dev

"Nullable object must have a value" exception after checking for null on a non-primitive/non-struct object

From Dev

Nullable objects must have value error

From Dev

Nullable object must have a value while using datepicker control with dropdown control

From Dev

ASP.NET MVC 5 Razor throws 'Nullable object must have a value' even when the object has value

From Dev

Calling AddDays on a Nullable DateTime object

From Dev

Object must have some value in its @XmlValue field

From Dev

Must Be Mapped. It has no default value and is not nullable

From Dev

How to parse nullable DateTime object in C#

From Dev

Stripe error: "The card object must have a value for 'number'" when creating a Customer

From Dev

How to determine if a runtime object is of a nullable value type

From Dev

Some problems using ToShortDateString() method on a nullable DateTime object, why?

From Dev

Convert nullable datetime object to specifc format while using html helper

From Dev

Some problems using ToShortDateString() method on a nullable DateTime object, why?

From Dev

Expression must have a pointer to object type in C

From Dev

Array definition - Expression must have a constant value

From Dev

C++ Expression must have constant value

From Dev

c++ expression must have a constant value

From Dev

Intellisense expression must have a constant value

From Dev

block and expression must have a const value error

From Dev

Expression must have constant value Eigen matrix

From Dev

Nullable DateTime List to Non Nullable DateTime List

From Dev

To Have An ID or Not To Have An ID - Regarding Value Object

From Dev

The type 'MyObject' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'Nullable<T>'

Related Related

  1. 1

    best method to solve Nullable object must have a value in datetime

  2. 2

    Linq: Nullable Object must have Value

  3. 3

    Decimal? - Nullable object must have a value

  4. 4

    "Nullable object must have a value" when Where uses a method?

  5. 5

    Nullable object must have a value. VB.NET

  6. 6

    Anonymous Type "Nullable object must have a value" Error

  7. 7

    "Nullable object must have a value" exception after checking for null on a non-primitive/non-struct object

  8. 8

    Nullable objects must have value error

  9. 9

    Nullable object must have a value while using datepicker control with dropdown control

  10. 10

    ASP.NET MVC 5 Razor throws 'Nullable object must have a value' even when the object has value

  11. 11

    Calling AddDays on a Nullable DateTime object

  12. 12

    Object must have some value in its @XmlValue field

  13. 13

    Must Be Mapped. It has no default value and is not nullable

  14. 14

    How to parse nullable DateTime object in C#

  15. 15

    Stripe error: "The card object must have a value for 'number'" when creating a Customer

  16. 16

    How to determine if a runtime object is of a nullable value type

  17. 17

    Some problems using ToShortDateString() method on a nullable DateTime object, why?

  18. 18

    Convert nullable datetime object to specifc format while using html helper

  19. 19

    Some problems using ToShortDateString() method on a nullable DateTime object, why?

  20. 20

    Expression must have a pointer to object type in C

  21. 21

    Array definition - Expression must have a constant value

  22. 22

    C++ Expression must have constant value

  23. 23

    c++ expression must have a constant value

  24. 24

    Intellisense expression must have a constant value

  25. 25

    block and expression must have a const value error

  26. 26

    Expression must have constant value Eigen matrix

  27. 27

    Nullable DateTime List to Non Nullable DateTime List

  28. 28

    To Have An ID or Not To Have An ID - Regarding Value Object

  29. 29

    The type 'MyObject' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'Nullable<T>'

HotTag

Archive