An overflow occurred while converting to datetime.

I'm trying to write a record to SQL CE using Linq to SQL and getting the following error message....

System.Data.SqlServerCe.SqlCeException: An overflow occurred while converting to datetime

Curiously, I'm not actually inserting a value into the DateTime field.

If I remove the DataTime attribute from my class then all is well.

Help (please) !
Who is Participating?
DodsworthConnect With a Mentor Author Commented:
Firstly my date column didn't like a null value even tho I set it to CanBeNull !

Fixed it by passing:

.sStartDate = DateTime.Now.ToUniversalTime

Open in new window

Aneesh RetnakaranDatabase AdministratorCommented:
try this format for the date  yyyymmdd
DodsworthAuthor Commented:
I'm not even writing a date to the table !
Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

your Linq2Sql class that holds the Column names has a DateTime column set correct?
public class MyTable
[Column(Name="MyDate" canbenull=true)]
public DateTime MyDate{get;set;}

Open in new window

I would reccomend changing to this:
[Column(Name="MyDate" canbenull=true)]
public DateTime? MyDate{get;set;}  //declare DateTime value as nullable

Open in new window

DodsworthAuthor Commented:
I'm using

 <Column> _
    Public Property sStartDate() As DateTime
            Return m_sStartDate
        End Get
        Set(value As DateTime)
            m_sStartDate = value
        End Set
    End Property
    Private m_sStartDate As DateTime

I tried <Column(DbType="DateTime", CanBeNull = True)

but still no good :(
DodsworthAuthor Commented:
Kelvin SparksCommented:
I usually see that message when the datetime being passed is outside of the range accepted by the database. Common if data has been converted from ACcess or similar - or there is a typo in the date and 2013 has been entered as 201.

Is nearly always a data issue.

DodsworthAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.