gpt4 book ai didi

vb.net - 如何为 TableAdapter 参数设置值

转载 作者:行者123 更新时间:2023-12-02 07:02:02 28 4
gpt4 key购买 nike

目标

我希望能够有两个组合框,其中一个是第二个组合框的父级或所有者。这意味着每当我在第一个 ComboBox 中选择一个值时,第二个 ComboBox 就会过滤其结果以显示与第一个 ComboBox 相关的相应值>.

例如:

ComoBox Filtering Example

注意:此示例已通过编程方式完成...我想了解如何使用 Visual Studio 的用户界面来完成此操作

<小时/>

现状

我有一个包含两个数据表的数据集,如下所示:

DataSet

如您所见,我的 BakerySubSectionsTableAdapter 中有一个名为 @FK_BakerySection 的参数。我想将其链接到 BakerySection PK_BakerySection 属性。

<小时/>

当前结果

这是我当前的结果:

Current Result

在我的 TableAdapter 中使用以下查询:

Query Builder

那么...我们如何使用用户界面为参数设置值?

最佳答案

如果您在两个表之间添加DataRelation,这很容易(IIRC,您可以简单地在数据集设计器中执行此操作)。

然后您只需将第二个 ComboBoxDisplayMember 设置为 ParentTable.NameOfRelation.NameToDisplay

<小时/>

这是一个完整的小示例:

enter image description here

<小时/>
Dim data = New DataSet()
Dim section = data.Tables.Add("Section")
section.Columns.Add("ID", GetType(Integer))
section.Columns.Add("Name", GetType(String))

Dim sub_section = data.Tables.Add("SubSection")
sub_section.Columns.Add("ID", GetType(Integer))
sub_section.Columns.Add("Name", GetType(String))
sub_section.Columns.Add("Section", GetType(Integer))

section.Rows.Add(New Object() {1, "Foo"})
section.Rows.Add(New Object() {2, "Bar"})

sub_section.Rows.Add(New Object() {1, "Sub Foo", 1})
sub_section.Rows.Add(New Object() {2, "Another Sub Foo", 1})

sub_section.Rows.Add(New Object() {3, "Sub Bar", 2})
sub_section.Rows.Add(New Object() {4, "bar bar bar", 2})
sub_section.Rows.Add(New Object() {5, "more bar", 2})

section.ChildRelations.Add("SectionToSub", section.Columns("ID"), sub_section.Columns("Section"))

Dim f = New Form()
Dim c1 = New ComboBox() With { _
.DataSource = data, _
.DisplayMember = "Section.Name", _
.ValueMember = "Id" _
}
Dim c2 = New ComboBox() With { _
.DataSource = data, _
.DisplayMember = "Section.SectionToSub.Name", _
.ValueMember = "Id" _
}
Dim fl = New FlowLayoutPanel()
fl.Controls.Add(c1)
fl.Controls.Add(c2)
f.Controls.Add(fl)
f.ShowDialog()

只需确保您的 BakerySubSections 已完全填充(无需参数)。

关于vb.net - 如何为 TableAdapter 参数设置值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23390646/

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