Solved

Linq to SQL Insert Problem

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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

685 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