0

I've been through a tough day facing this problem. In ent object, I have DiinputTanggal property as Date. In database, I have DiinputTanggal column as DateTime. When I try to insert the ent object into the database, I got the following error shown in the screenshot below. But when I debug, the property DiinputTanggal in ent object seems perfectly fine and nicely formatted. I have no idea where is my mistake.

enter image description here

0

1 Answer 1

1

Looking at your screenshot, it is probably the TaggalAktif property which is causing the overflow. .Net DateTimes default to DateTime.MinValue which cannot be represented in SQL DateTime.

You have several options

  • Initialize the DateTime to a value supported by Sql DateTime (in the range indicated by the error)
  • Change the DateTime to be nullable in both the class and database, (and ensure the property is initialized to null).
  • Use another Sql DataType to store the data e.g. DateTime2 or just Date if time isn't needed.
3
  • Actually, I don't give the value on TanggalAktif property, because TanggalAktif is nullable column. I don't get it why this is happen. Commented Dec 12, 2013 at 4:16
  • In addition to being nullable in the database, you will either need to make the class property Nullable Of DateTime as well, or have a custom mapping to map DateTime.MinValue to DBNull. Commented Dec 12, 2013 at 4:20
  • Yes indeed, I am declare TanggalAktif property in my model using ActiveRecord like this: <[Property]()> Public Overridable Property TanggalAktif() As Date Any wrong with this? If I commented this property, my code is work finely Commented Dec 12, 2013 at 4:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.