Filtering on DateTime in DataGrid results in crash #261

Closed
opened 2026-01-29 17:34:23 +00:00 by claunia · 2 comments
Owner

Originally created by @amazingalek on GitHub (Nov 19, 2021).

Describe the bug
Filtering on DateTime in DataGrid results in crash: Microsoft.Data.SqlClient.SqlException (0x80131904): Conversion failed when converting date and/or time from character string. (full stack trace below).

FormatString works fine for formatting column values, but the filtered date is formatted incorrectly and an error occurs when building the EF query. In both these cases it seems FormatString and FilterDateFormat are ignored and the date format of the environment/system is used instead.

I think the issues are related to this: when displaying the filtered date and building the EF query, column.GetFilterValue() is used. It returns the DateTime value as an object, but is used like a string, so it's just casted and no explicit formatting occurs.
I guess this isn't an issue in US, but that the DateTime format of my region (Oslo/Norway) is unexpected by Radzen and/or EF.

Full stack trace:

Error: Microsoft.Data.SqlClient.SqlException (0x80131904): Conversion failed when converting date and/or time from character string.
   at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at Microsoft.Data.SqlClient.SqlDataReader.TryHasMoreRows(Boolean& moreRows)
   at Microsoft.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean setTimeout, Boolean& more)
   at Microsoft.Data.SqlClient.SqlDataReader.Read()
   at Microsoft.EntityFrameworkCore.Storage.RelationalDataReader.Read()
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
   at System.Linq.Queryable.Count[TSource](IQueryable`1 source)
   at Radzen.Blazor.RadzenDataGrid`1.get_View()
   at Radzen.PagedDataBoundComponent`1.get_PagedView()
   at Radzen.Blazor.RadzenDataGrid`1.DrawGroupOrDataRows(RenderTreeBuilder builder, IList`1 visibleColumns)
   at Radzen.Blazor.RadzenDataGrid`1.<>c__DisplayClass6_0.<DrawRows>b__0(RenderTreeBuilder builder)
   at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)
   at Radzen.Blazor.RadzenDataGrid`1.BuildRenderTree(RenderTreeBuilder __builder)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
ClientConnectionId:64afdacd-03b8-4e8b-9607-0041a76485d1
Error Number:241,State:1,Class:16

To Reproduce
Steps to reproduce the behavior:

  1. Be in Oslo/Norway.
  2. Make a DataGrid with a DateTime column and filtering (only tested SimpleMode).
  3. Try to format the DateTime with FormatString and FilterDateFormat.
  4. Run the app and observe that the DateTime column values are formatted according to FormatString.
  5. Try to filter on a date and observe that the filtered date is not formatted according to FormatString or FilterDateFormat.
  6. Click Apply and experience a crash.

Expected behavior
The filtered date should be displayed according to FormatString or FilterDateFormat, and the DataGrid should update according to the DateTime filter without crashing, like it does for other columns.

Screenshots
None right now.

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Chrome
  • Version: 95.0.4638.69

Additional context

  • .NET 5
  • Radzen 3.12.2 (I tried many different versions, same issue)
Originally created by @amazingalek on GitHub (Nov 19, 2021). **Describe the bug** Filtering on DateTime in DataGrid results in crash: `Microsoft.Data.SqlClient.SqlException (0x80131904): Conversion failed when converting date and/or time from character string.` (full stack trace below). FormatString works fine for formatting column values, but the filtered date is formatted incorrectly and an error occurs when building the EF query. In both these cases it seems FormatString and FilterDateFormat are ignored and the date format of the environment/system is used instead. I think the issues are related to this: when displaying the filtered date and building the EF query, column.GetFilterValue() is used. It returns the DateTime value as an object, but is used like a string, so it's just casted and no explicit formatting occurs. I guess this isn't an issue in US, but that the DateTime format of my region (Oslo/Norway) is unexpected by Radzen and/or EF. Full stack trace: ``` Error: Microsoft.Data.SqlClient.SqlException (0x80131904): Conversion failed when converting date and/or time from character string. at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at Microsoft.Data.SqlClient.SqlDataReader.TryHasMoreRows(Boolean& moreRows) at Microsoft.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean setTimeout, Boolean& more) at Microsoft.Data.SqlClient.SqlDataReader.Read() at Microsoft.EntityFrameworkCore.Storage.RelationalDataReader.Read() at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext() at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query) at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression) at System.Linq.Queryable.Count[TSource](IQueryable`1 source) at Radzen.Blazor.RadzenDataGrid`1.get_View() at Radzen.PagedDataBoundComponent`1.get_PagedView() at Radzen.Blazor.RadzenDataGrid`1.DrawGroupOrDataRows(RenderTreeBuilder builder, IList`1 visibleColumns) at Radzen.Blazor.RadzenDataGrid`1.<>c__DisplayClass6_0.<DrawRows>b__0(RenderTreeBuilder builder) at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment) at Radzen.Blazor.RadzenDataGrid`1.BuildRenderTree(RenderTreeBuilder __builder) at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment) at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry) at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue() ClientConnectionId:64afdacd-03b8-4e8b-9607-0041a76485d1 Error Number:241,State:1,Class:16 ``` **To Reproduce** Steps to reproduce the behavior: 1. Be in Oslo/Norway. 2. Make a DataGrid with a DateTime column and filtering (only tested SimpleMode). 3. Try to format the DateTime with FormatString and FilterDateFormat. 3. Run the app and observe that the DateTime column values are formatted according to FormatString. 5. Try to filter on a date and observe that the filtered date is not formatted according to FormatString or FilterDateFormat. 7. Click Apply and experience a crash. **Expected behavior** The filtered date should be displayed according to FormatString or FilterDateFormat, and the DataGrid should update according to the DateTime filter without crashing, like it does for other columns. **Screenshots** None right now. **Desktop (please complete the following information):** - OS: Windows 10 - Browser: Chrome - Version: 95.0.4638.69 **Additional context** - .NET 5 - Radzen 3.12.2 (I tried many different versions, same issue)
Author
Owner

@amazingalek commented on GitHub (Nov 20, 2021):

I tested this on another computer and was not able to reproduce the crash. The system still controls the DateTime format, but it causes no issues with building the EF query.

On the computer where I experience the crash, the DB is in the cloud. The issue might be caused by a mismatch between the DateTime format of the server and my computer.

@amazingalek commented on GitHub (Nov 20, 2021): I tested this on another computer and was not able to reproduce the crash. The system still controls the DateTime format, but it causes no issues with building the EF query. On the computer where I experience the crash, the DB is in the cloud. The issue might be caused by a mismatch between the DateTime format of the server and my computer.
Author
Owner

@amazingalek commented on GitHub (Nov 22, 2021):

I found the issue, it was on my side. I used "datetime" in SQL table, changing it to "datetime2" solved the issue.

@amazingalek commented on GitHub (Nov 22, 2021): I found the issue, it was on my side. I used "datetime" in SQL table, changing it to "datetime2" solved the issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#261