将 System.Linq.IorderedEnumerable 转换为 DataView

发布于 2024-08-07 07:37:59 字数 643 浏览 9 评论 0原文

我正在尝试从正在查询类型化数据集的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽清梦 2024-08-14 07:37:59

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文