formview datetime error

Tongue Tied

Hello, I am having the following problem. I have created a formview to edit information in a SQL Server 2K table. One of the fields is a date field. The data type is set to datetime and Null values are allowed.

Whenever I try to update the information, I get the following stack error.

Any help would be appreciated...

Exception Details: System.FormatException: String was not recognized as a valid DateTime.

Source Error:

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.

Stack Trace:


[FormatException: String was not recognized as a valid DateTime.]
System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) +2136462
System.DateTime.Parse(String s, IFormatProvider provider) +26
System.Convert.ToDateTime(String value, IFormatProvider provider) +49
System.String.System.IConvertible.ToDateTime(IFormatProvider provider) +10
System.Convert.ChangeType(Object value, TypeCode typeCode, IFormatProvider provider) +528
System.Web.UI.WebControls.SqlDataSourceView.AddParameters(DbCommand command, ParameterCollection reference, IDictionary parameters, IDictionary exclusionList, String oldValuesParameterFormatString) +609
System.Web.UI.WebControls.SqlDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +363
System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +78
System.Web.UI.WebControls.FormView.HandleUpdate(String commandArg, Boolean causesValidation) +1144
System.Web.UI.WebControls.FormView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +643
System.Web.UI.WebControls.FormView.OnBubbleEvent(Object source, EventArgs e) +95
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.FormViewRow.OnBubbleEvent(Object source, EventArgs e) +109
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +115
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +134
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +180
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5670

[2884 byte] By [sck10] at [2007-12-17]
# 1
I just tried this scenario using the Northwind database Orders table. It has two columns, ShippedDate and OrderDate, both of which allow null values. The Update works fine, for this reason:

When you clear the TextBox for the date in GridView, a String.Empty value is posted. The BoundField object for this field has ConvertEmptyStringToNull="true" by default, so the value gets converted to null before passing to the SqlDataSource. If you happen to be using a TemplateField, you can set ConvertEmptyStringToNull="true" on the asp:Parameter object in the SqlDataSource UpdateParameters collection instead. It should also be true by default, however.

By any chance, have you set ConvertEmptyStringToNull="false" on either the BoundField or Parameter object? This might explain why it isn't working.

Hope this helps,
Bradley
The Web Platform and Tools Team

Bradley at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Installing and Registering Visual Studio 2005 Express Editions...