与组合框绑定到数据库的问题 [英] Probleam with combobox which bound to database

查看:70
本文介绍了与组合框绑定到数据库的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的组合框有问题.
我有4个组合框绑定到数据库.

问题是,如果我在第一个组合框中选择列表项之一,则其他第二个,第三个和第四个组合boxex将显示相同的项目.
这给我带来了一个问题,因为我正在创建一个表单来计算定价商品.

第一个组合框必须具有与第二,第三和第四项不同的项目列表.
对于您的信息也是如此,所有这些组合框都连接到具有列项目名称的1个表.

请告知或告诉我如何做到这一点,如果我在第一个组合框中选择一个项目列表,则第二,第三和第四个组合框可以显示不同的列表项目.

我需要解决这个问题.

这是我的编码,如果有误,请更正我的编码


Hi,

I have a problem with my combo box.
I have 4 combo boxes which are bound to database.

The problem is if I choose one of the list item in 1st combo box then other second , third and forth combo boxex will display the same item.
This is causing me a problem because I am creating a form to calculate a priced item.

First combo box must have different item list from second, third and forth.
For your info too, all these combo boxes are connected to 1 table with column item name.

Please advise or show me how I can make it that if I choose one item list in first combo box then second , third and forth combo box can display with different list items.

I need to solve this issue.

Here is my coding, Please correct my coding if it have a mistake


Private Sub ItemNameComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ItemNameComboBox.SelectedIndexChanged

connection.ConnectionString = "Data Source=Danawa;Initial Catalog=Store;Integrated Security=True "

connection.Open()
cmd = New SqlCommand("SELECT * FROM ItemIn WHERE ItemName = '" & Me.ItemNameComboBox.Text & "' ", connection)

Dr = cmd.ExecuteReader()
If Dr.Read = False Then
MsgBox("Item Name Is Not Found!!", MsgBoxStyle.Exclamation)
Else
Me.price.Text = Dr("ItemPrice").ToString
End If
Dr.Close()
connection.Close()

推荐答案

1.收集要在组合框中显示的项目,该项目可以实现诸如List(项目)或数据集之类的集合(例如,IList)的接口,并用您的数据填充它.
2.您的组合框中有3个感兴趣的成员:
-数据源:这是您的商品的集合
-DisplayMember:在ComboBox中显示为文本的内容
-ValueMember:如果要绑定以显示描述,但要查询Key或其他内容

如果使用数据集,则可以编写combobox.DisplayMember ="table1.desc"和combobox.ValueMember ="table1.id"(据我所记得).

有关更多信息,请参阅Apress第8章中的"VB 2005中的Pro .NET 2.0 Windows窗体和自定义控件".您也可以在Google图书上查看它.
1. Collect the items you want to display in the combobox in something that implements an interface of a collection(IList for example) like List (Of Items) or even a Dataset and fill it with your data.
2.In your Combobox there are 3 members of interest:
- DataSource: this is the collection of your items
- DisplayMember: what is shown as text in your ComboBox
- ValueMember: if you want to bind to display the description, but want to query for a Key or something

If you use a dataset, you can write combobox.DisplayMember="table1.desc" and combobox.ValueMember="table1.id"( as far as i remember).

For more information look into "Pro .NET 2.0 Windows forms and custom controls in VB 2005" from Apress, chapter 8. You can also view it on google books.


这篇关于与组合框绑定到数据库的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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