将 System.Linq.IorderedEnumerable 转换为 DataView
我正在尝试从正在查询类型化数据集的 linq 查询表达式获取 DataView。结果为 System.linq.IOrderedEnumerable 类型。但是我无法将此类型转换为 Dataview,尽管互联网上的一些示例表明 AsDataView 函数应该可以工作,但是您能否解释一下为什么 AsDataView 方法没有在查询中公开。
示例代码:
Dim SortedRates = From rateDetail In ratesDetail _
Select RateName = ("(" & rateDetail.RateType & ") - " & rateDetail.Name), _
RateID = rateDetail.RateID _
Order By RateName Ascending
Dim dv1 As New DataView
dv1 = SortedRates
我无法执行 SortedRates.AsDataView,也无法直接将 SortedRates 转换为 dv1。
请帮忙。
谢谢。 库拉姆。
I am trying to get the DataView from a linq query expression which is querying a typed dataset. The result lands in a type of System.linq.IOrderedEnumerable. But i'm not able to convert this type to a Dataview although a few examples on the internet say that AsDataView function shoudl work but could you please throw some light on why the method AsDataView is not exposed on the query.
example code:
Dim SortedRates = From rateDetail In ratesDetail _
Select RateName = ("(" & rateDetail.RateType & ") - " & rateDetail.Name), _
RateID = rateDetail.RateID _
Order By RateName Ascending
Dim dv1 As New DataView
dv1 = SortedRates
I cannot do SortedRates.AsDataView and i also cannot directly cast SortedRates to dv1.
Please help.
Thanks.
Khurram.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AsDataView
方法仅适用于 DataRow 集合。您想要做的事情是不可能的,因为 DataView 必须包装 DataTable。
执行此操作的唯一方法是从查询创建一个 DataTable 并为该 DataTable 创建一个 DataView。
为什么需要数据视图?
The
AsDataView
method only applies to collections of DataRows.What you're trying to do is impossible because a DataView must wrap a DataTable.
The only way to do this is to create a DataTable from your query and make a DataView for that DataTable.
Why do you need a DataView?