By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,344 Members | 1,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,344 IT Pros & Developers. It's quick & easy.

get values of selected listbox items to another listbox

P: 25
hello, I have a form with 2 listboxes. Listbox1 is populated with symptoms. If a symptom is selected, listbox2 will show the related illnesses having that symptom. Here's my working code:
Expand|Select|Wrap|Line Numbers
  1. Call Connect()
  2.         With Me
  3.             Dim dt As New DataTable
  4.             STRSQL = "select illness from diagnose where symptom_name = '" & lstSymptoms.SelectedItem & "'"
  5.             Try
  6.                 lstrelated.Items.Clear()
  7.                 myCmd.Connection = myConn
  8.                 myCmd.CommandText = STRSQL
  9.                 reader = myCmd.ExecuteReader
  10.                 If (reader.Read()) Then
  11.                     reader.Close()
  12.                     adptr.SelectCommand = myCmd
  13.                     adptr.Fill(dt)
  14.                     lstrelated.DisplayMember = "illness"
  15.                     lstrelated.ValueMember = "illness"
  16.                     For Each row As DataRow In dt.Rows
  17.                         lstrelated.Items.Add(row("illness"))
  18.                     Next
  19.                 End If
  20.             Catch ex As Exception
  21.                 MsgBox(ex.Message)
  22.             End Try
  23.         End With
It works perfectly, but what I really wanted is that, for example, when user select symptom1 it will show the related illnesses containing symptom1, then if user select another symptom (ex. symptom3) it will show illnesses containing symptom 1 and 3 and so on. How can I do this? Please help me, I have to finish this today. God bless..
Feb 5 '13 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 9,731
Use the SQL In Operator in your SQL query. This will allow you to select rows that match anything "in" a list.

Aside from that, you should really use Parameters with your SQL commands.

Feb 5 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.