views:

27

answers:

1

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?

+1  A: 

--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>

tsimbalar
no, this is not the case
Andrey
if it's still not OK, we'll have to wait for a real VB Developer ;)
tsimbalar
Tried but the same result. I'm looking at creating a new DataTable and then iterate through the DataSet and for each row, run the LINQ and add the result to this new DataTable. Not having so much luck with it yet though. Getting a lot of casting errors. Ideas are welcome. Thanks so far guys...
Soeren