Answered by:

Question

I have a formview that shows data from one row in a table. The table has HireDate, BirthDate as "date" datatype and LastModifiedTime and CreatedTime as "datetime" datatype. The formview shows up OK on page load, but when I try to edit the data and click
Update, it gives me this error.

HireDate, CreatedTime and LastModifiedTime are set to Allow nulls. I get this exception if I kepp these fields empty in Edit mode. What is the reason for this errror? Also, there is another table with the same specifications and the same functionality works
fine with that table, that is, if I enter null values in Hiredate, it does not return error.

Other Info: I am using LINQDataSource for this formview and database is SQL Server 2008

Answers

There are validators in place to check if the date entered is MM/dd/yyyy format and the user has to type it in. Even if I enter today's date, it does not return any error but saves the date as 1/1/0001 in the database. If I leave it blank, which is an OK
condition as that field is not required, then I get this exception.

So for the HireDate textbox if I enter : 11/18/2011, then the database saves it as 1/1/0001 and if I keep it blank, then it returns this error.

I actually deleted the LinqDatasource and the FormView, closed the project and reopened it and crezted everything anew just like before and it now works fine *fingers crossed* and hopefully won't start giving any more troubles. But I would like to know what's
with the SQL Server datatypes...

I think that it is existing a difference ( in the code ) between the treatement of your both tables in the LINQDataSource code. If it is a LINQ problem ( or maybe a problem in the formview ), a moderator may move your thread , but i have no idea to
which forum.

A little advice : when an error/exception occurs, display at least the StackTrace of the exception ( you have to use a try/catch in your code ) and you will know the line number and the code file name where the error is occuring.For the moment, i have not
enough informations to try to help you efficiently ( but i am not a specialist of FormView or LINQ )

Don't hesitate to post again for more help or explanations.

Have a nice day

Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

When the page loads, the LinqDataSource simply reads an ID from the session and loads appropriate data into the formview. The formview loads correctly. When I click on "New" or "Edit", the proper templates load and if I make editions and keep the date fields
blank (they are not required), then I get this error.

I tried to enter today's date in there and when I checked the database, I saw "01/01/0001 12:00:00 AM" in the database. The only exception I get is when I keep it blank.

As per Papy's sugestion, I am pasting here the Stack trace I get when I enter empty data in HireDate, CreatedTime and LastModifiedTime fields:

Server Error in '/' Application.

SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.

Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Please, coul you explain how your code is using this date ? What control do you use to type your date ? If it is DateTimePicker or similar, you must use the Value property and not the Text property which must be transmitted to the database

The formview is connected to a LinqDataSource which selects one row from the table and loads into the FormView.

Formview has Edit, Insert and Item templates. Item Template is default and when I click "New" or "Edit" buttons on the formview, they load The Edit Template and Insert Template respectively. Also, these templates have textboxes in the formview. This is the
FormView Datacontrol. i have not added any control inside it. I simply added the DataSources and Formview and Gridview and configured all of these, so I didn't have to write any code as these controls do everything on their own, just like ObjectDataSources.
I never saw this problem with any of my other tables or similar pages, and I have quite a few of them, all of which work fine.

To be clear, you have to set the SqlDateTime to DbNull to avoid your problem when you don't put a date ( DbNull is a specific value for the null values ).Or your configuration of the textbox is incorrect

"I never saw this problem with any of my other tables or similar pages" : are you sure that you have already a textbox related to a date which is nullable ?

Have a nice day

Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

There are validators in place to check if the date entered is MM/dd/yyyy format and the user has to type it in. Even if I enter today's date, it does not return any error but saves the date as 1/1/0001 in the database. If I leave it blank, which is an OK
condition as that field is not required, then I get this exception.

So for the HireDate textbox if I enter : 11/18/2011, then the database saves it as 1/1/0001 and if I keep it blank, then it returns this error.

I actually deleted the LinqDatasource and the FormView, closed the project and reopened it and crezted everything anew just like before and it now works fine *fingers crossed* and hopefully won't start giving any more troubles. But I would like to know what's
with the SQL Server datatypes...