当前位置: 动力学知识库 > 问答 > 编程问答 >

asp.net - Am trying to sort datatable dt, but its not working. Time Elapsed is my column name in dt. want to sort by DESC

问题描述:

public static DataTable resort(DataTable dt)

{

string sortByColumnsStr = "Time Elapsed DESC";

DataView dtview = new DataView(dt);

dtview.Sort = sortByColumnsStr;

DataTable dtsorted = dtview.ToTable();

return dtsorted;

}

网友答案:

Embed the column name with square brackets, like this:

string sortByColumnsStr = "[Time Elapsed] DESC";

You can eventually take a look at this: http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/1f37f760-b479-4b4a-a2db-0e828812ac0e/

分享给朋友:
您可能感兴趣的文章:
随机阅读: