Solved

Linq to SQL Insert Problem

Posted on 2014-04-09
2
230 Views
Last Modified: 2014-04-11
I have an entity class as below, but when I try to add a new row without specifying an EndDate, I get the error..

System.Data.SqlServerCe.SqlCeException: An overflow occurred while converting to datetime

If I add a row with an EndDate then all is fine.

<Table> _
Public Class Notes

    <Column(IsDbGenerated:=True, IsPrimaryKey:=True)> _
    Public Property Id() As Integer
        Get
            Return m_Id
        End Get
        Set(value As Integer)
            m_Id = value
        End Set
    End Property
    Private m_Id As Integer

    <Column> _
    Public Property StartDate() As System.Nullable(Of Date)
        Get
            Return m_StartDate
        End Get
        Set(value As System.Nullable(Of Date))
            m_StartDate = value
        End Set
    End Property
    Private m_StartDate As DateTime

    <Column(CanBeNull:=True)> _
    Public Property EndDate() As System.Nullable(Of Date)
        Get
            Return m_EndDate
        End Get
        Set(value As System.Nullable(Of Date))
            m_EndDate = value
        End Set
    End Property
    Private m_EndDate As DateTime

    <Column> _
    Public Property Note() As String
        Get
            Return m_Note
        End Get
        Set(value As String)
            m_Note = value
        End Set
    End Property
    Private m_Note As String
End Class

Open in new window

0
Comment
Question by:Dodsworth
2 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 39989390
Hi Dodsworth;

Have you tried making the data type assigned to the property match that of the backing store as shown below?

   <Column(CanBeNull:=True)> _
    Public Property EndDate() As System.Nullable(Of DateTime)
        Get
            Return m_EndDate
        End Get
        Set(value As System.Nullable(Of DateTime))
            m_EndDate = value
        End Set
    End Property
    Private m_EndDate As System.Nullable(Of DateTime)

Open in new window

0
 
LVL 1

Author Comment

by:Dodsworth
ID: 39993744
Yes that's fixed it thanks. Strange as the code was generated by SQLMetal.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

790 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