I am trying to pull the contents of an AS/400 file back to a data-bound .NET WinForms DataGridView (VS 2010). The query itself is no problem, and I am able to bind everything using the DataSource property of the grid. Data comes back with no issues.
The problem I am having is that all date/time fields come back as string literals, making it impossible to sort. Moreover, it comes back using our default AS/400 formats (yyyy-dd-mm and hh.mm.ss). I would like them to come back as actual Date/Time fields so that they can be sorted and I can control the output format (I would prefer MM/dd/yyyy and hh:mm:ss AMPM). I tried combining the two fields into one using the TIMESTAMP format, but that just gave me a combined string.
I would like to avoid doing any field massaging if at all possible, and I would like to keep the table data-bound for ease of coding, although if I have to turn off column auto-generation I will do so. I would also like to avoid doing any intermediary LINQ queries, as I lose the ability to sort by columns out of the box (and the examples I have seen online for adding this back in are all long and painful).
Can anybody suggest anything? Thanks!
EDIT: Code example. SQL to query the values (with names changed to protect the innocent) is:
SELECT MYDATE, MYTIME, TIMESTAMP(MYDATE, MYTIME)
FROM LIBNAME.FILENAME
WHERE <blah blah blah>
SQL query gets written to a DataTable via an OleDbDataAdapter.Fill command.
Dim myTable as New DataTable
Using adapter As New OleDbDataAdapter
adapter.SelectCommand = New OleDbCommand(<sql statement>, <AS/400 Connection>)
adapter.Fill(myTable)
Return myTable
End Using
DataTable gets stuffed into a DataGridView:
grid.DataSource = FunctionCallToGrabTheDataAbove
Pretty straightforward (and trying to keep it that way if possible)