Solved

An overflow occurred while converting to datetime.

Posted on 2013-11-08
9
894 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
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

770 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