1/1/0001 12:00:00 AM not updating SQL 2008 Date field

It is just weird and gives me a headache. I looked through my code and I do not see any logical errors causing it.

Any other date set for my DateDime variable of my Date of birth in my class works when I add it as a value in my conn.AddParam, but when I send back 1/1/0001 12:00:00 AM (which was sent setting it to MinValue) in the SQL 2008 date field, it is still the default value that I set to null in the database for this field:

conn.AddParam("@birthDate", birthDate);

Date of birth - type DateTime. It is set to DateTime.MinValue; I don’t understand why it won’t take it.

+3
source share
5 answers

, , , 1 1753 , SQL Server.

+4

, . birthDate (12:00 AM), SQL DateTime Date. 01.01.10001 SQL DateTime, . @birthDate birth.Date.Date.

0

SQL Server 2008:

: - (--) 0001-01-01 9999-12-31.Its 1

: hh: mm: ss: nnnnnnn, 00: 00: 00.0000000 - 23: 59: 59: 9999999 100

DateTime2: YYYY-MM_DD hh: mm: ss: nnnnnnnm 0001-01-01 00: 00: 00.0000000 - 999-12-31: 59 9999999, - 100 nano

DateTimeOffset: . : YYYY-MM-DD hh: mm: ss [.nnnnnnn] [+/-] hh: mm 0001-01-01 00: 00: 00.000000 - 9999-12-31 23: 59: 50.9999999.storage 8 10 .

0

DateTime is the type of value. Therefore, if the DateTime variable was not assigned, the value will be the default, which will be DateTime.MinValue. Therefore, when explicitly setting the date of birth of DateTime.MinValue, it was processed in the way that it was not assigned at all (for example, as null) and thus was replaced with the default value for this parameter in the stored proc.

0
source

Source: https://habr.com/ru/post/1722137/


All Articles