Solved

An overflow occurred while converting to datetime.

Posted on 2013-11-08
9
866 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now