473,765 Members | 2,019 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

get values of selected listbox items to another listbox

25 New Member
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
  24.  
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
1 1347
Frinavale
9,735 Recognized Expert Moderator Expert
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.

-Frinny
Feb 5 '13 #2

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

Similar topics

1
1594
by: kent | last post by:
Hi All, On my form, I have 2 listboxes that get populated with the correct items. I have 4 buttons between the 2 boxes. The first 2 buttons are used to move the selected item back and forth between the boxes. That works fine. The last 2 are used to move all the listbox items (whether they're selected or not) that are in 1 box over to the other box. After the move, I want the other box to be empty. I am calling clear() and
0
1034
by: bh_jodokast | last post by:
It's pretty easy to do a drag from one listbox to another listbox when using Windows.Forms, but on the web, forms are handled differently. My plan is to use two listboxes and a DHTML HTC file to change the cursor (like if you drag out of bounds the cursor changes to "nodrag") My friend has a javascript snippet that does this too, but... I like to go hog-wild!
5
4415
by: Dave | last post by:
Hi All, I have a windows form that contains 2 listboxes and 2 buttons. The listbox on the right is populated by a database routine (This is the easy part). The listbox on the left is populated by 1 or more selected items from the listbox on the right after clicking an Add button. Clicking a "Remove" button will remove the item from the left listbox and restore it back to the right box.
1
2945
by: anjupt | last post by:
Hi, I have 2 listboxes with data fetched from database so for both the listboxes datasource is set .i tried to move data from one listbox to another listbox but Error"An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll Additional information: Cannot modify the Items collection when the DataSource property is set. " comes up .how can i move data from one listbox to another listbox Thank you
3
5768
by: perrycheung221 | last post by:
Hi guys, I got 2 listboxes in a window form, one on left and one on right. The 1st listbox have some items while the 2nd listbox is empty. Also there are 2 buttons between the 2 listboxes which used to move item from/to the 1st and 2nd listbox My problem here is that after I bind the data to the 1st listbox (from a dataTable, using DisplayMember and ValueMember), and I try to move 1 of the item from this 1st listbox to the 2nd listbox...
1
12882
by: dkohel | last post by:
I have 2 list boxes on my form. I am trying to populate listbox B with the selection from listbox A. I have set multi-select in both boxes to Extended... The user will select the items from listbox A and click an Add button that will then copy the items to listbox B. Then for each item in B, I need to add them to a database. If there are 3 items in listbox B, I need to add 3 line items to table B... Any ideas?
0
1010
by: savakis | last post by:
Can onyone please help me please. I have duplicate items in column A:A which I find via combobox1. These items are placed in listbox1. I then fill in textbox1 and textbox2 for column C and D, and then fill the found cells with some text. This is OK. I then have option2 where I am trying to put text in found cells that are only selected in my listbox1 this is set for multiselect. The option2 does not work. Can anyone check this out please....
1
1909
by: SuriAug05 | last post by:
Hello, I have created one web page. In that i have used two listboxes. Now i want to drag an item from one listbox and drop the same item in another listbox. And also want to rearange the items without any help of buttons or any other controls. can anyone help me in this problem. Thanks,
5
11024
by: sreenu123 | last post by:
Hi, I want to read from values from database and add to listbox then transfering items from one listbox to another listbox using C#.NET. Can any one give source code. Thanks in advance sree
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9835
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5277
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.