如何设置值到TableAdapter参数 [英] How To Set a Value to a TableAdapter Parameter

查看:223
本文介绍了如何设置值到TableAdapter参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要能够有两个ComboBoxes,其中一个是第二个的父级或所有者。这意味着每当我在第一个 ComboBox 中选择一个值时,第二个 ComboBox 将过滤它的结果,与 ComboBox 相关的值

I want to be able to have two ComboBoxes where one is the parent or owner of the second one. This means that whenever I select a value in the first ComboBox, the second ComboBox will filter it's results to display the corresponding values related to the first ComboBox.

例如:

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

Note: This example has been completed programmatically... I want to figure out how to do it using the user interface of Visual Studio

我有一个数据集,其中包含两个数据表:

I have a dataset with two DataTables like so:

img src =https://i.stack.imgur.com/510Bh.pngalt =DataSet>

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

As you can see, I have a parameter in my BakerySubSectionsTableAdapter called @FK_BakerySection. I want to link that to the BakerySection's PK_BakerySection attribute.

以下是我当前的结果:

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

Using the following query in my TableAdapter:

所以...如何使用用户界面为参数设置值?

So ... How do we set a value to a parameter using the User Interface?

推荐答案

你在两个表之间添加一个 DataRelation (IIRC,你可以在DataSet设计器中这样做)。

It's easy if you add a DataRelation between your two tables (IIRC you can simply do this in the DataSet designer).

您只需要将第二个 ComboBox DisplayMember 设置为 ParentTable.NameOfRelation.NameToDisplay

Then you only have to set the DisplayMember of your second ComboBox to ParentTable.NameOfRelation.NameToDisplay.

这是一个小而完整的例子:

Here's a small, complete example:

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 已完全填充(不需要参数)。

Just make sure your BakerySubSections is completly filled (no need for the parameter).

这篇关于如何设置值到TableAdapter参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆