I am trying to convert all DateTime values in a DataTable to strings. Here is the method I'm using:
private static void ConvertDateTimesToStrings(DataTable dataTable) { if (dataTable == null) { return; } for (int rowIndex = 0; rowIndex < dataTable.Rows.Count; rowIndex++ ) { for (int i = 0; i < dataTable.Columns.Count; i++) { DateTime dateTime; try { dateTime = (DateTime)dataTable.Rows[rowIndex][i]; } catch (InvalidCastException) { continue; } dataTable.Rows[rowIndex][i] = dateTime.ToString("dd.MM.yyyy hh:mm:ss"); } } }
After executing this line:
dataTable.Rows[rowIndex][i] = dateTime.ToString("dd.MM.yyyy hh:mm:ss");
I check the value of dataTable.Rows [rowIndex] [i] and see that it is still a DateTime, not a string. Why is this happening and how can I solve it?
Edit: I am trying to do this because I am struggling with api, and unfortunately I have no choice which component to use.
source share