Asp.net Date Binding Issue with Nulls

Posted by Matthew Kruskamp on Stack Overflow See other posts from Stack Overflow or by Matthew Kruskamp
Published on 2008-11-12T06:43:20Z Indexed on 2010/05/29 13:52 UTC
Read the original article Hit count: 251

Filed under:
|
|
|

I have a nullable date in my database. I am connecting to it with a LinqDataSource, and binding with a FormView. It allows you to place dates fine, but if you remove the date I need it to insert the null value to the db. It is instead throwing an exception.

<asp:TextBox ID="TxtStartDate" runat="server" 
                    Text='<%# Bind("StartDate", "{0:MM/dd/yyyy}") %>' />

Works fine if you place a date in it, but if you delete the date out of it and save, you get System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM. How do I make it send null?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about datetime