【发布时间】:2018-10-12 05:24:59
【问题描述】:
我正在尝试对数据表进行排序。所以,做了以下代码:
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
谢谢
【问题讨论】:
-
克隆可能不会复制表名。您仍然可以自己设置表名或使用 index 来代替
-
谢谢。好的,有什么深层的 CopyToDataTable() 东西吗?
-
我不确定,但如果您尝试
ds.Tables[DataTableName].DefaultView.Sort =" FieldName SortDirection";会发生什么情况@
标签: c# asp.net linq datatable metadata