本文介绍了如何通过更改VB.Net中的组合框中的项目从Access 2007数据库填充列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有
我只是在VB.Net和Access 2007中开发一个项目,我只是陷入了我只需要从Access 2007数据库填充列表框但我改变了组合框中的项目列表框应相应更改。我有填充列表框的代码但更改组合框项目后项目没有变化。
请指导我这方面。
Dear all
I am just developing a project in VB.Net and Access 2007 and i just got stuck at a point where I just need to Populate a Listbox from Access 2007 database but if I change an item from the combo box the listbox should change accordingly. I have the code to populate the listbox but items are not changing after changing combo box items.
Please guide me in this regard.
Private Sub frmneworder_Load(sender As Object, e As EventArgs) Handles MyBase.Load
cmbmain.Text = "Select Main Item"
Call loadinvestigations()
End Sub
Sub loadinvestigations()
Con.Open()
Dim cmd As New OleDbCommand("select * from items", Con)
Dim dr As OleDbDataReader = cmd.ExecuteReader
While dr.Read
lstitem.Items.Add(dr(1).ToString.ToUpper)
End While
dr.Close()
Con.Close()
Private Sub cmbmain_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbmain.SelectedIndexChanged
Con.Open()
Dim cmd As New OleDbCommand("select item_name from items where cat_name='" & txtopd.Text & "'", Con)
Dim dr As OleDbDataReader = cmd.ExecuteReader()
While dr.Read
lstitem.Items.Add(dr(1).ToString.ToUpper)
End While
dr.Close()
Con.Close()
End Sub
推荐答案
Private Sub cmbmain_SelectedValueChanged(sender As Object, e As EventArgs) Handles cmbmain.SelectedValueChanged
lstitem.Items.Clear()
Con.Open()
Dim cmd As New OleDbCommand("select * from items where cat_name='" & cmbmain.Text & "'", Con)
Dim dr As OleDbDataReader = cmd.ExecuteReader
While dr.Read
lstitem.Items.Add(dr(1).ToString.ToUpper)
End While
dr.Close()
Con.Close()
End Sub
我感谢Mt Maciej Los的帮助。
谢谢
I thank Mt Maciej Los for his kind help.
Thank you
这篇关于如何通过更改VB.Net中的组合框中的项目从Access 2007数据库填充列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!