开发者

Query a DataSet using LINQ

I have a DataSet that I fill with a SQL select query. I then need to perform an extra query on this DataSet to filter the data some more, using LINQ to DataSet. I then want to hook this LINQ result up to some Data Control (Repeater or GridView) It is not working so well though.

Here 开发者_开发问答is what I've tried so far:

Dim sql As String = "SELECT * from someTable"
Dim ds As New System.Data.DataSet()
ds = db_functions.DB_GetDS(sql) 'Helper function that returns a dataset, not important

Dim res = (From s In ds.Tables(0) Where s.Field(Of Date)("date") > Date.Today Select s).ToList

GridView1.DataSource = res
GridView1.DataBind()

When I run the page, using a GridView, there is a GridView with one row and two fields - RowError and HasRows, and there is no data in the row. One row would be the correct number in this example, so the where clause seems to be evaluated correctly. But why no data?

If I Use a Repeater instead, the page is blank.

Any ideas?


--EDIT--

I'm not to sure about the Vb syntax and everything, but it seems that your problem is that you are not running your LINQ query against the good elements... I would replace

Dim res = (From s In ds.Tables(0) Where s.Field(Of Date)("date") > Date.Today Select s).ToList

with

Dim res = (From r In ds.Tables(0).Rows Where r("date") > Date.Today Select r)

Then your datasource would actually be a IEnumerable<DataRow>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜