使用 LINQ 查询数据集

发布于 2024-09-27 07:09:34 字数 669 浏览 1 评论 0原文

我有一个用 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 技术交流群。

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

发布评论

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

评论(1

二货你真萌 2024-10-04 07:09:34

--编辑--

我不确定 Vb 语法和所有内容,但似乎你的问题是你没有针对好的元素运行 LINQ 查询...
我会替换

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

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

然后你的数据源实际上是一个 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

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>

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