?
Solved

An overflow occurred while converting to datetime.

Posted on 2013-11-08
9
Medium Priority
?
1,024 Views
Last Modified: 2016-02-10
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) !
0
Comment
Question by:Dodsworth
8 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 39633909
try this format for the date  yyyymmdd
0
 
LVL 1

Author Comment

by:Dodsworth
ID: 39633938
I'm not even writing a date to the table !
0
 
LVL 12

Expert Comment

by:ShazbotOK
ID: 39633992
your Linq2Sql class that holds the Column names has a DateTime column set correct?
Example:
[Table(Name="Blah")]
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

0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 1

Author Comment

by:Dodsworth
ID: 39634277
I'm using VB.net

 <Column> _
    Public Property sStartDate() As DateTime
        Get
            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 :(
0
 
LVL 1

Author Comment

by:Dodsworth
ID: 39638909
Anyone?
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 39664838
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.

Kelvin
0
 
LVL 1

Accepted Solution

by:
Dodsworth earned 0 total points
ID: 39665402
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

0
 
LVL 1

Author Closing Comment

by:Dodsworth
ID: 39677012
Fixed
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question