Link to home
Start Free TrialLog in
Avatar of Dodsworth
Dodsworth

asked on

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) !
Avatar of Aneesh
Aneesh
Flag of Canada image

try this format for the date  yyyymmdd
Avatar of Dodsworth
Dodsworth

ASKER

I'm not even writing a date to the table !
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

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 :(
Anyone?
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
ASKER CERTIFIED SOLUTION
Avatar of Dodsworth
Dodsworth

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Fixed