使用 LINQ 查询数据集
我有一个用 SQL 选择查询填充的数据集。然后,我需要使用 LINQ to DataSet 对此 DataSet 执行额外的查询以进一步过滤数据。然后我想将此 LINQ 结果连接到某些数据控件(Repeater 或 GridView),但它工作得不太好。
这是我到目前为止所尝试过的:
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()
当我使用 GridView 运行页面时,有一个 GridView 包含一行和两个字段 - RowError 和 HasRows,并且该行中没有数据。在本例中,一行是正确的数字,因此 where 子句的计算似乎是正确的。但为什么没有数据呢?
如果我使用中继器,则页面为空白。
有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
--编辑--
我不确定 Vb 语法和所有内容,但似乎你的问题是你没有针对好的元素运行 LINQ 查询...
我会替换
为
然后你的数据源实际上是一个
IEnumerable
--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
with
Then your datasource would actually be a
IEnumerable<DataRow>