Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding DB2 (iSeries) DATE/TIME/TIMESTAMP columns to a WinForms DataGridView
    text
    copied!<p>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.</p> <p>The problem I <strong>am</strong> 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. </p> <p>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).</p> <p>Can anybody suggest anything? Thanks!</p> <p>EDIT: Code example. SQL to query the values (with names changed to protect the innocent) is:</p> <pre><code>SELECT MYDATE, MYTIME, TIMESTAMP(MYDATE, MYTIME) FROM LIBNAME.FILENAME WHERE &lt;blah blah blah&gt; </code></pre> <p>SQL query gets written to a DataTable via an OleDbDataAdapter.Fill command.</p> <pre><code>Dim myTable as New DataTable Using adapter As New OleDbDataAdapter adapter.SelectCommand = New OleDbCommand(&lt;sql statement&gt;, &lt;AS/400 Connection&gt;) adapter.Fill(myTable) Return myTable End Using </code></pre> <p>DataTable gets stuffed into a DataGridView:</p> <pre><code>grid.DataSource = FunctionCallToGrabTheDataAbove </code></pre> <p>Pretty straightforward (and trying to keep it that way if possible)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload