Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Combo box and select query

Author  Topic 

mulefeathers
Starting Member

12 Posts

Posted - 2012-10-31 : 15:20:15
I have a basic windows form in VB. I am using the following code to connect to a SQL database. The database has two tables. The goal here is have a user make a selection in one combo box and populate the other with only the records that match the query. The first combobox is populated by table tblsymbols column process. The second is populated by tblparts and should fill the box with all part numbers where the process columns match.

Private Sub frmParts_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.TblPartsTableAdapter.Fill(Me.KanbanDataSet.tblParts)

Me.TblSymbolsTableAdapter.Fill(Me.KanbanDataSet.tblSymbols)
Dim sqlprocess As String = Nothing
sqlprocess = "SELECT * from tblSymbols"
cboprocess.DataSource = KanbanDataSet.Tables(1)
cboprocess.ValueMember = "Process"
cboprocess.SelectedValue = -1


End Sub

Private Sub ProcessComboBox_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cboprocess.SelectedIndexChanged

Dim strprocess As String = cboprocess.Text
Dim strpart = "SELECT PartNumber FROM tblParts WHERE Process = strprocess"

End Sub

Any help would be great.

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-10-31 : 16:57:47
The easy answer is to contacenate the strProcess variable correctly:
Dim strpart = "SELECT PartNumber FROM tblParts WHERE Process = '" & strprocess &"'"
That will only let you pick one /processvalue at a time. If that is all you need then you are good to go. This sounds like a learning exercise so you may not need or want to go further, but if you did, you might look into using a parameterized query or passing the string or ID (if there is one) to a stored proecedure rather that workiggn with inline SQL.
Go to Top of Page

mulefeathers
Starting Member

12 Posts

Posted - 2012-11-01 : 08:21:28
This is more a learning exercise than anything else. I haven't worked with VB since VS 2003. Our company will start moving this way within the next 12 months and I'm trying to learn all that is new and everything I have forgotten. Thanks for the help.
Go to Top of Page
   

- Advertisement -