'SQL doesn't accept my minimum date from C#
I use the layer2 cloud connector to sync between Sharepoint DB (right) and SQL Server database (left). I sync from right to left only. I make a dynamic column on the right side, which has the following code:
if (String.IsNullOrEmpty(NächstesFSKontrolldatum.ToString()))
{
return DateTime.Parse("1753-01-01T00:00:00.000");
}
else
{
return NächstesFSKontrolldatum;
}
In the first part I try to return the minimum SQL Server datetime
value, which our system needs instead of null.
But I get the following error:
The provider 'System.Data.SqlClient' marked the row 'xyz' as erroneous: SqlDateTime-Überlauf; muss zwischen 1/1/1753 12:00:00 AM und 12/31/9999 11:59:59 PM liegen.
Which means in English there is an overflow, because it is out of the range.
I tried to use
DateTime sqlMinDateAsNetDateTime = System.Data.SqlTypes.SqlDateTime.MinValue.Value;
and return that, but the namespace Data
isn't known in my program's environment.
How to pass the value correctly to write the real minimum date?
Solution 1:[1]
The support of layer2 made my day! The following works fine: if (NächstesFSKontrolldatum > DateTime.Parse("1/1/1753 12:00:00")) return NächstesFSKontrolldatum; return DateTime.Parse("1/1/1753 00:00:00");
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Andreas Schröder |