Sorting a dataTable by date

Hello everyone,
My problem is that I cannot sort my dataTable by date. I tried to use sorting filters ( with the Select command ) and also using a DataView. But nothing changes.

Is there a way to achieve this programmatically
Best regards.


Answer this question

Sorting a dataTable by date

  • oaix

    Here is my code :
    DataView dataView = dataTable.DefaultView;

    dataView.Sort = "FolderDate";
    //
    // foreach row from the selected data
    //
    foreach (DataRowView dataRow in dataView)
    {
    ....
    }

    What I mean by "nothing changes.." is that the dataView is not sorted.
    Thanks anyway



  • Suresh .M.V

    around 5000


  • mobigital

    Can you check the type of the FolderDate DataColumn Is it a DateTime type or a string type



  • Chidu

    Assuming that you have a DataColumn of the type DateTime named "Date" you can sort as follows:

    DataView dataView = dataTable.DefaultView;
    dataView.Sort = "Date";
    listBox1.DataSource = dataView;

    When you say nothing changes, what exactly are you looking at



  • KnobCreek

    just checked it.. it is DateTime..


  • raja760

    Are there many items in the datatable

  • Taya Cool

    It is possible that the sort is delayed for as long the dataview is not fully initialized. Can you confirm that when you set a breakpoint before the foreach loop construct that the Sort property of the Dataview is set to the date datacolumn

  • Sorting a dataTable by date