views:

425

answers:

1

Hi All,

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.

+2  A: 

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?

SLaks