Sorted dataview to datatable

喜欢而已 提交于 2019-11-29 17:18:10

问题


I have the following method:

private DataTable getsortedtable(DataTable dt)
{
    dt.DefaultView.Sort = "Name desc";
    //I would need to return the datatable sorted.
}

My issue is that I cannot change the return type of this method and I have to return a DataTable but i would like return it sorted.

Are there any magic hidden property of dt.DefaultView to return the dt sorted?


回答1:


 private DataTable getSortedTable(DataTable dt)
 {
    dt.DefaultView.Sort = "columnName DESC";
    return dt.DefaultView.ToTable();
  }



回答2:


do this

private DataTable getsortedtable(DataTable dt)
{
    //do the operation for sort   
    return dataView.ToTable();
}


来源:https://stackoverflow.com/questions/3987150/sorted-dataview-to-datatable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!