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.
Asked
Active
Viewed 93 times
0

andrefadila
- 647
- 2
- 9
- 36
1 Answers
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 justDate
if time isn't needed.

StuartLC
- 104,537
- 17
- 209
- 285
-
Actually, I don't give the value on `TanggalAktif` property, because `TanggalAktif` is nullable column. I don't get it why this is happen. – andrefadila Dec 12 '13 at 04: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`. – StuartLC Dec 12 '13 at 04: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 – andrefadila Dec 12 '13 at 04:43