从SQL填充C#组合框,并根据选择限制结果 [英] Populating C# combobox from SQL and restrict results based on choice

查看:161
本文介绍了从SQL填充C#组合框,并根据选择限制结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将来自SQL表的一些数据绑定到C# ComboBox 。我想要实现的是以下:

I am binding some data from a SQL table into a C# ComboBox. What I want to achieve is the following:

假设我们在SQL中有3个表

Say we have 3 tables in SQL


  1. 房间(卧室,浴室,厅)

  2. 床,浴室,衣柜)

  3. StuffProperty (DoubleBed,HotRunningWater,Clothes)。

  1. Room (Bedroom, Bathroom, Hall)
  2. Stuff (Bed, Bath, Wardrobe)
  3. StuffProperty (DoubleBed, HotRunningWater, Clothes).

我的目标是限制第二个和第三个 ComboBox 值,基于第一个 ComboBox ,即:

My goal is to restrict the second and the third ComboBox values, based on the choice of the first ComboBox, i.e:

第一个 ComboBox 包含卧室,浴室,如果用户选择了浴室,第二个 ComboBox 只包含浴缸而不是床或衣柜,第三个 ComboBox 只包含HotRunningWater ,不是DoubleBed或Clothes

The first ComboBox contains Bedroom, Bathroom, Hall. If the user chooses Bathroom, the second ComboBox contains only Bath and not Bed or Wardrobe and the third ComboBox only contains HotRunningWater, not DoubleBed or Clothes

如何在不按下按钮的情况下将查询发送回SQL?

How can I send a query back to SQL without pushing a button, 'live'?

此外,我应该使用存储过程将Room,Stuff和StuffProperty值映射在一起,并在C#代码中调用它们(这是我想要的)。或者我应该编写整个过滤的东西在C#(例如使用开关)?

Also, should I use Stored procedures to map Room, Stuff and StuffProperty values together and invoke them in C# code (this is what I would prefer)? Or should I write the whole filtering stuff in C# (for example using switches)?

在这一个上真的很无知,甚至不知道有没有办法通知最近的选择的SQL,而不按下按钮。我使用的列只是为了说明这个问题。

Really clueless on this one and not even sure if there's any way to 'inform' the SQL of a recent choice without pushing a button. The columns I used are only to illustrate the problem.

此外,我知道这个问题在这里已经问了几次,但我发现是VB代码

Also, I'm aware this question has been asked here a couple of times, but all I found were VB code and I need it to be sorted with a Stored Procedure and C#, or C# only.

推荐答案

你需要挂钩到一个存储过程和C#事件的组合框,很可能selectedIndexChanged或类似。这就是你如何得到活效果。你需要挂钩到第一个组合框的事件,然后填充第二个。

You would need to hook onto an event of the combobox, most likely selectedIndexChanged or similar. This is how you get the "live" effect. You would need to hook onto the event of the first combobox and then populate the second.

然后在第二个事件中你需要填充第三个。

Then in the event of the second you need to populate the third.

如何使用metro向导我不确定,但希望有一个gameplan你可以找到所需的代码。

How you go about this using metro wizard I am not to sure but hopefully with a gameplan you can find the required code.

这篇关于从SQL填充C#组合框,并根据选择限制结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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