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.
Add a comment
|
1 Answer
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.
-
Actually, I don't give the value on
TanggalAktif
property, becauseTanggalAktif
is nullable column. I don't get it why this is happen.andrefadila– andrefadila12/12/2013 04:16:47Commented 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 mapDateTime.MinValue
toDBNull
.StuartLC– StuartLC12/12/2013 04:20:50Commented 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 finelyandrefadila– andrefadila12/12/2013 04:43:46Commented Dec 12, 2013 at 4:43