我的DataSet命名为专辑,其中包含四个DataTables.Name,这些表的顺序是
我需要按字母顺序排列数据集(相册)中的所有这些DataTable。如下所示
我在谷歌搜索过但没有解决方案
答案 0 :(得分:3)
试试这个,它将传递给你的数据集并返回一个新的数据集,其中的表格按名称排序。
Imports System.Collections.Generic
Function OrderDatatables(ByVal ds As DataSet) As DataSet
Dim tableList As New SortedList(Of String, DataTable)
Dim sortedDataset As New DataSet
For Each table As DataTable In ds.Tables
tableList.Add(table.TableName, table)
Next
For Each tableItem As KeyValuePair(Of String, DataTable) In tableList
sortedDataset.Tables.Add(tableItem.Value.Clone())
Next
Return SortedDataset
End Function
<强>更新强>
添加DataTable值
Function OrderDatatables(ByVal ds As DataSet) As DataSet
Dim tableList As New SortedList(Of String, DataTable)
Dim sortedDataset As New DataSet
For Each table As DataTable In ds.Tables
tableList.Add(table.TableName, table)
Next
For Each tableItem As KeyValuePair(Of String, DataTable) In tableList
sortedDataset.Tables.Add(ds.Tables(tableItem.Value.Clone().ToString()).Copy())
Next
Return SortedDataset
End Function