-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filtering on DateTime column with non-midnight time component doesn't return valid FilterString #51
Comments
Hello @will-scc. DateTime converstion works if the format of the DateTime is the same of you o.s. culture I think the problem should be there. Can you run the Sample project first and check if it works there for you? |
Hi @davidegironi, sorry for the delayed reply. I wanted to make sure I tested it on the machine that had the problem. The sample project does work on the machine, so it's definitely an application-specific problem. I've forced the formatting of the column to match the culture ( However, this still isn't recognising the time component and, as a result, the filtering isn't working: As you can see, it's only picking up the dates not the times. My current culture is Even if I remove all formatting and just have it default, it seems to be coming out as Any ideas what might be going on here? |
Small bit of additional info. I've setup a brand new project to test this and the issue persists. The complete code of my test:
|
I think I've narrowed down the problem to something related to loading data from databases (maybe the I've taken the working sample project and replaced the I tried this with both
Which loads like this: The filtering then doesn't work: Again, same problem in that the time component is not recognized. Note the FilterString. I've double checked that the DataType of that column is definitely I'm at a loss to think what the cause of this could be... Any ideas? |
Instead of adding the full datatable, iterate the table adapter and fill a single row, then add the row to the dataset binded to the bindingdatasource of the grid. |
Do you know why adding a complete DataTable would cause this behaviour? It's very weird that it only happens on DateTime columns in this specific situation, everything else works fine. Having to change how to load data from my database into datatables by avoiding using |
I've never investigate on this. I prefer to uncouple the DataAdapter cause it's related to the DB you are using. You should try with other DB sources, or google for something like "DataAdapter.Fill datetime conversion". Also looking at your query, it performs an union between tables, at first i will try with just one table, than makes thing little more complex. |
I have a DateTime column with the format
dd/MM/yyyy HH:mm
:The values in the underlying DataSource are from a database so have non-midnight time componennts, e.g.
25/06/2020 12:22:44
.This is recognised as a DateTime column:
However, when you try to filter by a specific date (you can't filter by a specific hour) it returns no rows .
If I inspect the
FilterString
that's created, it is producing this:"((Convert([DATE RAISED], 'System.String') LIKE '%25/06/2020 00:00:00%'))"
The reason this filter returns no rows is because, for example,
25/06/2020 12:22:44
is not like25/06/2020 00:00:00
(due to the time component).This same problem exists even if I force the column Format like this:
dgv.Columns("DATE RAISED").DefaultCellStyle.Format = "dd/MM/yyyy HH:mm:ss"
. TheFilterString
is still setting any time component to00:00:00
. I assume this is because here we're only changing the displayed value and not the underlying value in the DataSource to which the filter is being applied.If I truncate these dates at the database/query level, the filtering works. This is obviously not an ideal fix when I need to display the time component.
The text was updated successfully, but these errors were encountered: