将Sorted DataView转换为Typed DataTable

时间:2014-06-16 11:03:44

标签: c# dataview

我有一个名为Account的强类型DataTable,我在Account.FullName:

上排序
DataView dvAccount = new DataView(dtAccount)
dvAccount.Sort = "FullName desc";

在我的查询之后,fullname是我的DataSet中生成的字段,基于名字,中间,最后等。这意味着不幸的是,按SQL查询排序不是一个选项。

首先,我试图像这样得到表格:

dtAccount = dvAccount.Table()

但这给了我Dataview所基于的原始表格。所以在线阅读后我发现我应该使用DataView.ToTable()函数而不是DataView.Table()函数:

dtAccount = dvAccount.ToTable() as dsAccount.AccountDataTable; // returns null
dtAccount = ((dsAccount.AccountDataTable) dvAccount.ToTable()); // gives Convertion to Typed Datatable Error

现在我遇到了我的帐户表格是强类型的问题。因此,在线搜索告诉我,我可以使用DataTable.Merge()函数或每行DataTable.ImportRow(),但这些被告知是一个非常繁重的过程,因为每一行都会在类型上进行检查。什么是这种情况的最佳实践解决方案?

0 个答案:

没有答案
相关问题