如何使用 VB.NET 将 SQL 查询的结果连接到导航栏?

发布于 2024-12-17 08:33:34 字数 200 浏览 5 评论 0原文

我有一个关于在 Visual Basic 中使用数据库的基本问题。 我正在使用 OleDb 连接。我拖放了编辑框 从 DataDource 视图。这会自动放置表格导航- 表格上的栏。当我运行它时,效果很好。 但是我希望能够使用 SQL 语句在表中进行搜索。 如何将 SQL 查询的结果连接到导航栏,以便 编辑框自动获取记录的值,而无需 手动分配每个文本框?

非常感谢。

I have a basic question about using a database with Visual Basic.
I'm using a OleDb connection. I have dragged and dropped editboxes
from the DataDource view. This automatically places the table navigation-
bar on the form. When I run it this works fine.
However I want to be able to search within the table, with an SQL statement.
How can I connect the results from the SQL query to the navigation bar,such that
the editboxes automatically take the values of the record without having to
assign every textbox manually?

Thank you very much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

空心空情空意 2024-12-24 08:33:34

这个小片段似乎有效,尽管您必须为表指定排序列,并且如果您想按多个字段排序,则在 Find 调用中传递与您正在搜索的值相对应的 Object() 类型的数组for (按照排序值的顺序。请告诉我它是否适合您或者您是否有任何其他问题。

'**** Sample table structure for Database1Dataset.Table1
'   Col1        Col2        Col3
'(row)  "Row1.Col1" "Row1.Col2" "Row1.Col3"
'(row)  "Row2.Col1" "Row2.Col2" "Row2.Col3"
'(row)  "Row3.Col1" "Row3.Col2" "Row3.Col3"

Dim dv As DataView = Me.Database1DataSet.DefaultViewManager.CreateDataView(Database1DataSet.Table1)
dv.Sort = "Col1"

Me.Table1BindingNavigator.BindingSource.Position = dv.Find("Row2.Col1")

这是一个包含多个排序列的示例

Dim dv As DataView = Me.Database1DataSet1.DefaultViewManager.CreateDataView(Database1DataSet1.Table1)
Dim FindValues(1) As Object

dv.Sort = "Col1,Col3"

FindValues(0) = "Row2.Col1"
FindValues(1) = "Row2.Col3"

Me.Table1BindingNavigator.BindingSource.Position = dv.Find(FindValues)

This little snippet seems to work, although you have to specify the Sort columns for your table, and if you want to sort by multiple fields then on the Find call you pass an array of Object() types that correspond to the values you are searching for (in the order of the Sort values. Let me know if it works for you or if you have any other questions about it.

'**** Sample table structure for Database1Dataset.Table1
'   Col1        Col2        Col3
'(row)  "Row1.Col1" "Row1.Col2" "Row1.Col3"
'(row)  "Row2.Col1" "Row2.Col2" "Row2.Col3"
'(row)  "Row3.Col1" "Row3.Col2" "Row3.Col3"

Dim dv As DataView = Me.Database1DataSet.DefaultViewManager.CreateDataView(Database1DataSet.Table1)
dv.Sort = "Col1"

Me.Table1BindingNavigator.BindingSource.Position = dv.Find("Row2.Col1")

Here is an example with multiple sort columns

Dim dv As DataView = Me.Database1DataSet1.DefaultViewManager.CreateDataView(Database1DataSet1.Table1)
Dim FindValues(1) As Object

dv.Sort = "Col1,Col3"

FindValues(0) = "Row2.Col1"
FindValues(1) = "Row2.Col3"

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