This is a migrated thread and some comments may be shown as answers.

[Solved] Exception on bound datetime column with NULL in db

3 Answers 172 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 06 May 2008, 09:58 PM
When the Grid goes into Edit mode with a GridDateTime column with picker, if the column is NULL (a valid value in the db in this case) I get an exception.

This is bound to a LINQ datasource, is there any way to handle this exception or cause a default value to appear?

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 07 May 2008, 11:26 AM
Hello Rob,

Can you provide a bit more info about this exception (full stack trace)?

Best wishes,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Rob
Top achievements
Rank 1
answered on 07 May 2008, 06:43 PM

Here is the error and stack trace below.  Note that the field is a SQL2005 datetime field that is null.  If I put a valid datetime in the field, it works fine so the exception only happens when the field is null, and only if the column is datetime column as listed below:

<telerik:GridDateTimeColumn UniqueName="PlanDocsInServiceDate" PickerType="DateTimePicker" HeaderText="PlanDocsInServiceDate" Visible="false" DataField="PlanDocsInServiceDate">

</telerik:GridDateTimeColumn>

ERROR:

String was not recognized as a valid DateTime.

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.

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) +2291962
   System.DateTime.Parse(String s, IFormatProvider provider) +26
   System.Convert.ToDateTime(String value, IFormatProvider provider) +56
   System.String.System.IConvertible.ToDateTime(IFormatProvider provider) +10
   System.Convert.ChangeType(Object value, TypeCode typeCode, IFormatProvider provider) +528
   System.Web.UI.WebControls.Parameter.GetValue(Object value, String defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean ignoreNullableTypeChanges) +264
   System.Web.UI.WebControls.Parameter.get_ParameterValue() +66
   System.Web.UI.WebControls.ParameterCollection.GetValues(HttpContext context, Control control) +254
   System.Web.UI.WebControls.LinqDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +172
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +17
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149
   Telerik.Web.UI.GridTableView.PerformSelect() +23
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
   Telerik.Web.UI.GridTableView.DataBind() +318
   Telerik.Web.UI.RadGrid.DataBind() +142
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
   System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +69
   System.Web.UI.Control.EnsureChildControls() +87
   System.Web.UI.Control.PreRenderRecursiveInternal() +50
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041


Version Information: Microsoft .NET Framework Version:2.0.50727.1434; ASP.NET Version:2.0.50727.1434
0
Rosen
Telerik team
answered on 08 May 2008, 12:24 PM
Hi Rob,

Unfortunately I was unable to reproduce this unwanted behavior locally. Can you please double check that the DataField property is pointing to a valid field name? I attached a simple project that tries to re-create the described issue, can you please modify it as the error to appear and send it back to us (attached to a formal ticket)? Thus we will do everything possible to give you an accurate resolution.

Best wishes,
Rosen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Rob
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Rob
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or