troubleshooting Question

my rows are not sorting correctly in datatable

Avatar of tentavarious
tentavarious asked on
.NET Programming
7 Comments1 Solution3647 ViewsLast Modified:
Hello experts i have one datatable called newtable the first field contains a date time stamp that i converted to a string in military time.  I am trying to fill another table called dt2 from the new table, but when i loop through the data in dt2 the rows are not sorted correctly any ideas?
The reason for this is that i want to convert the time back to normal once it is sorted then bind to datagrid, and i cant not sort a string field correctly by date time unless i use military time.  The date field has to remain a string because i also insert characters into it.  Currently this sort works but its military time:
"Datagrid3.DataSource = New DataView(newtable, "", "DatePLC", DataViewRowState.CurrentRows)".  I cant figure out why my other sort is not working.


  Dim dv As New DataView
            Dim ds As New DataSet
            ds.Tables.Add(newtable)
            With dv
                .Table = ds.Tables(0)
                .Sort = "DatePLC"
                .RowStateFilter = DataViewRowState.CurrentRows
            End With
            Dim dt2 As New DataTable
            dt2 = dv.Table
            Dim value2a As String
            x = 0
            For x = 0 To dt2.Rows.Count - 1
                value2a = dt2.Rows(x).Item(0)  ' i am using this to check the value
           ' when i get the sort working covert to normal time
                x += 1
            Next

'Currently i am using this and it works except that it displays the military time.
 Datagrid3.DataSource = New DataView(newtable, "", "DatePLC", DataViewRowState.CurrentRows)
            Datagrid3.DataBind()
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros