Solved

Linq to SQL Insert Problem

Posted on 2014-04-09
2
232 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
[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
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

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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