Stef_99
(Stef)
1
I use code as below. (sort data column Planned Start)
dt_Result.AsEnumerable().OrderBy(Function(row) row.Field(Of DateTime)("Planned Start")).CopyToDataTable()
But show error Specified cast is not valid.
My data in excel as below.
Please guide me for solve it.
Thank you
vrdabberu
(Varunraj Dabberu)
2
Hi @Stef_99
Try the below syntax:
dt_Result.AsEnumerable().OrderBy(Function(row) DateTime.ParseExact(row.Field(Of String)("Planned Start"), "d/M/yyyy HH:mm", System.Globalization.CultureInfo.InvariantCulture)).CopyToDataTable()
Regards
Yoichi
(Yoichi)
3
Hi,
To isolate cause, can you check content of the datatable at Locals panel when error occurs in debug run?
Is there any invalid data including empty? And also check format style of the date time data.
Regards,
Stef_99
(Stef)
4
@vrdabberu If I have 2 format (d/m/yyyy HH:MM , dd/mm/yyyy HH:MM:SS)
How to edit your code ?
Thank you
vrdabberu
(Varunraj Dabberu)
5
Hi @Stef_99
Try this:
dt_Result.AsEnumerable().OrderBy(Function(row) DateTime.ParseExact(row.Field(Of String)("Planned Start"), {"d/M/yyyy HH:mm","dd/MM/yyyy HH:mm:ss"}, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None)).CopyToDataTable()
Regards
1 Like
Stef_99
(Stef)
6
@vrdabberu It error as below.
vrdabberu
(Varunraj Dabberu)
7
Hi @Stef_99
Can you share the syntax you have written
Regards
system
(system)
Closed
10
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.