gpt4 book ai didi

mysql - 如何从 SQLDataSource 中过滤数据

转载 作者:行者123 更新时间:2023-11-29 03:30:28 26 4
gpt4 key购买 nike

我正在尝试按文本框名称 PostCode1 从 SQLDataSource POSTCODE_Data 中过滤数据。

我通过使用 .Rowfilter 属性来执行此操作,但它不起作用。结果 POSTCODE_Data 仍未过滤。

我需要做什么才能得到想要的结果?

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim dv As DataView
Dim recPostDes As String
Dim recMiles As Integer
dv = CType(POSTCODE_Data.Select(DataSourceSelectArguments.Empty), DataView)
dv.RowFilter = "POSTCODE = '" & PostCode1.Text & "%'"
recPostDes = CType(dv.Table.Rows(0)(3), String)
recMiles = CType(dv.Table.Rows(0)(5), Integer)
If recMiles > 0 Then
Des1.Text = recPostDes
Mile1.Text = recMiles
End If
End Sub

最佳答案

首先,看起来您正在尝试创建一个 Like表达。如果是这样,将 = 更改为 Like

dv.RowFilter = "POSTCODE Like '" & PostCode1.Text & "%'"

DataView
"Represents a databindable, customized view of a DataTable for sorting, filtering, searching, editing, and navigation. The DataView does not store data, but instead represents a connected view of its corresponding DataTable. Changes to the DataView’s data will affect the DataTable. Changes to the DataTable’s data will affect all DataViews associated with it." - MSDN -

现在,这是您的问题:您访问的是基础表 (dv.Table) 而不是 View 。

recPostDes = CType(dv.Item(0).Row.Item(3), String)
recMiles = CType(dv.Item(0).Row.Item(5), Integer)

或者

recPostDes = CType(dv(0)(3), String)
recMiles = CType(dv(0)(5), Integer)

关于mysql - 如何从 SQLDataSource 中过滤数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31352982/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com