Solved

Linq to SQL Insert Problem

Posted on 2014-04-09
2
221 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 62

Accepted Solution

by:
Fernando Soto earned 500 total points
Comment Utility
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
Comment Utility
Yes that's fixed it thanks. Strange as the code was generated by SQLMetal.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

9 Experts available now in Live!

Get 1:1 Help Now