我正在尝试对数据表进行排序。因此,执行以下代码:
var dataTable = ds.Tables[DataTableName];
DataTable tempDataTable;
tempDataTable = dataTable.Clone();
tempDataTable = dataTable.AsEnumerable()
.OrderBy(x => x.Field<string>("fieldname"))
.ThenBy(x => x.Field<string>(sortColumn)).CopyToDataTable();
// issue here. it doesnt return the original table name but "Table1"
string tableN = tempDataTable.TableName;
ds.Tables.Remove(dataTable);
ds.Tables.Add(tempDataTable); // add the sorted data table
谢谢
答案 0 :(得分:3)
如果要对数据表进行排序,则无需复制/克隆它。
DataTable dataTable = Common.LoadFromDB();
dataTable.DefaultView.Sort = "fieldname ASC, " + sortColumn + " DESC";
dataTable.DefaultView.ToTable();