C# 使用ADO.Net数据集和TableAdapter使用筛选器填充combox
我有一个带有数据集和tableadapter的windows窗体C# 使用ADO.Net数据集和TableAdapter使用筛选器填充combox,c#,ado.net,C#,Ado.net,我有一个带有数据集和tableadapter的windows窗体 Table1 [id, action, info] Table2 [id, actionId, command] private void cbActions_SelectedIndexChanged(object sender, EventArgs e) { this.optionsTableAdapter.Fill(this.actionsDS.Options); BindingSou
Table1 [id, action, info]
Table2 [id, actionId, command]
private void cbActions_SelectedIndexChanged(object sender, EventArgs e)
{
this.optionsTableAdapter.Fill(this.actionsDS.Options);
BindingSource source1 = new BindingSource();
source1.DataSource = actionsDS;
source1.Filter = "ActionId = " + cbActions.SelectedValue;
cbOptions.DataSource = source1;
}
我不知道如何根据第一个组合框(cbActions)过滤sedond组合框(cbOptions)
在sql中,我将使用“选择actionid=5的选项”,但是,为了简单起见,我尝试使用内置的ado.net数据集和数据表
这必须很容易,我必须很接近。昨天几个小时都在想这件事
int actionId = 5;
ActionsDS.OptionsDataTable optionsDt = optionsTableAdapter.GetByActionId(actionId);
cbOptions.DataSource = optionsDt;
处理数据关系可能更简单—您的CardDataSet中有3个表—制造商、型号、修剪。它们之间都有数据关系,比如说它们被命名为ManufactureModel和ModelTrim 打开“数据源”窗口,(查看菜单-其他窗口)并展开每个节点。您将看到制造商、模型和修剪有顶级节点,但在制造商下有模型,在制造商下有修剪(根模型下有另一个修剪) 将制造商拖动到窗体以创建DataGridView,将制造商的子级模型拖动到窗体,并拖动模型的子级修剪 您现在应该有3个bindingsources,但关键是:
- 制造商bindingsource绑定到数据集表
- 模型bs绑定到制造商bs,并将datamember设置为ManufacturerModel关系的名称
- trim bs绑定到模型bs并具有ModelTrim的datamember