Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8035037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:11:50+00:00 2026-06-05T02:11:50+00:00

Hi and thanks in advance: So I’m trying to pull a table from an

  • 0

Hi and thanks in advance:

So I’m trying to pull a table from an SQL database and sort it on the “Date From” (DtFr) column, which represents the start of a lease. I thought it would be as easy as this:

Dim XmlReader As New XmlNodeReader(xmlDoc)
Dim ds As New DataSet
ds.ReadXml(XmlReader)
myDt = ds.Tables("Cam")
If myDt IsNot Nothing AndAlso myDt.Rows.Count > 0 Then
    Dim dv As New DataView(myDt)
    dv.Sort = "DtFr ASC"
    myDt = dv.ToTable(False, "Id", "Name", "Amount", "Unpaid", "DtFr")
End If

But as you might have guessed this is not working (new user, can’t post images it’s just a picture of the dates out of order).

enter image description here

Could it be because at some point along the data retrieval it’s no longer of type Date and it’s a string or something? If I use simpler dates, like 1/1/2012, 1/2/2012, 1/3/2012 or 1/1/2012, 2/1/2012, 3/1/2012 etc. it sorts alright, but as you’ll notice above, if i have varied months, it sorts it out of order.

I’ve tried messing with the culture, thinking it could be that it’s sorting them on the months before the year to no avail… I’m at a loss, any help, ideas, or direction to something helpful would be great.

Much Appreciated,
Josh

EDIT:
You’re a genius, thanks so much. You were right about the string value. I added a data column called sortDtFr to the datatable and gave it System.DateTime as a datatype and iterated through the rows setting the new column’s value equal to the old one casted as a Date. Here’s the code for those interested:

ds.ReadXml(XmlReader)

myDt = ds.Tables("Cam")
myDt.Columns.Add(New DataColumn("sortDtFr", System.Type.GetType("System.DateTime")))
For Each row As DataRow In myDt.Rows
    row("sortDtFr") = CDate(row("DtFr"))
Next
If myDt IsNot Nothing AndAlso myDt.Rows.Count > 0 Then
    Dim dv As New DataView(myDt)
    dv.Sort = "sortDtFr ASC"
    myDt = dv.ToTable(False, "Id", "Name", "Amount", "Unpaid", "DtFr", "sortDtFr")
End If
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T02:11:51+00:00Added an answer on June 5, 2026 at 2:11 am

    The reason why your records are sorted in that way is because the datatype of that DataColumn of your DataTable (Cam) is System.String (by default). Try changing it to System.DateTime.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thanks in advance for help. I am trying to set the ip address of
Thanks in advance, I am trying to redirect anyone who types in example.com or
Thanks in advance for any help. I have the following code which when clicked
Thanks in advance for your response. I am trying to create a stacked bar
Thanks in advance for any advice or tips! I have a booking table in
Hi and thanks in advance, I am writing a Sudoku Solver which uses OCR
Thanks in advance for any help. I've got two combo boxes which I'd like
thanks in advance for your help. I'm currently trying to create a w3c standards
Thanks in advance any help. I'm trying to get one of my controller methods
Thanks in advance for your help experts. I want to be able to copy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.