我有一個名爲foldername
,documentname
的列的Datatable。數據如下:使用C#對多列進行數據表排序
FolderName DocumentName
Folder1 HR[D] Document
Folder1 ___----'
Folder1 Asp_example.pdf
Folder2 SD
Folder3 Heavy_weight
Folder3 Accesorial Services
如何alphabetically
排序DocumentName在.Net Framework 2.0
基於文件夾名稱。
我們試過的解決方案是在下面,但是它佔用了太多的時間,因爲它包含了超過1200000條記錄。
int counter=0;
while (counter < searchDT.Rows.Count){
string FolderName = Convert.ToString(searchDT.Rows[counter]["Folder Name"]);
string exp = "[Folder Name] like '" + FolderName + "'";
if (FolderName.Contains("%") || FolderName.Contains("_") || FolderName.Contains("[]") || FolderName.Contains("'"))
exp = "[Folder Name] like '" + EscapeLikeValue(FolderName) + "'";
string sortExpression = "[Document Name] ASC";
DataRow[] drfoldername = searchDT.Select(exp, sortExpression);
foreach (DataRow row in drfoldername)
drfoldernameDT.ImportRow(row);
counter += drfoldername.Length;
}
你提到這個信息是從數據庫中獲得的,那麼你爲什麼不在SQL查詢中執行ORDER BY子句?否則,你是否嘗試過使用DataView而不是DataTable? –