Tuesday, March 24, 2015

Date and time check constraints in Dexterity

I'm using C# to insert date/time fields into a Dexterity-generated table, and i'm getting the following error:

The INSERT statement conflicted with the CHECK constraint "CK__<tablename>__Starti__027755D3". The conflict occurred in database "GPDAT", table "dbo.<tablename>", column 'StartingDate'.

Date constraint = time must be 00:00:00
Time constraint = date must be 1/1/1900

DateTime is immutable, so the way to zero out these values is to make a new DateTime object using the constructor DateTime(year, month, day, hour, minute, second), passing in the year/month/date from your DateTime object, and then 0's for hour/minute/second, or the opposite of that if it's going into a time field.

No comments:

Post a Comment