Wednesday, May 5, 2010

SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM

When you try assign a only time to a datetime and save it you are going to get an an exception like the one in the subject.

i have added to eXpand an SqlDateTimeOverFlowValueConverter to help you deal with that

public class SqlDateTimeOverFlowValueConverter:ValueConverter {

    public override Type StorageType {

        get { return typeof(DateTime); }

    }

 

    public override object ConvertToStorageType(object value) {

        if (value!= null) {

            var dateTime = new DateTime(1753, 1, 1);

            if (dateTime>(DateTime) value) {

                var time = ((DateTime) value).TimeOfDay;

                return dateTime.AddTicks(time.Ticks);

            }

        }

        return value;

    }

 

    public override object ConvertFromStorageType(object value) {

        return value;

    }

}

Subscribe to XAF feed
Subscribe to community feed

DiggIt!
blog comments powered by Disqus