?
Solved

An overflow occurred while converting to datetime.

Posted on 2013-11-08
9
Medium Priority
?
965 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 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
Independent Software Vendors: 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!

 
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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

764 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