Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27355

vb 2008 getting all listbox items

$
0
0
hello, this is my first post here and is beginning to learn vb2008. I am working on my project now but I came to a problem that I don't know how to solve. I have a form with 3 listboxes and a button. Listbox1(lstSymptoms) is populated with symptoms from the database. When a symptom is selected, it is then listed in listbox2(lstSelected). Now when diagnose button is clicked, it should get the symptoms from lstSelected and diagnose from the database table the illness where this symptoms in lstSelected is present, then display the result to listbox3(lstIllness). My database table's structure is: f_id, illness, symptoms. So far here's my code:
Code:

Call Connect()
 
        Dim dt As New DataTable
        Dim cmd As New MySqlCommand
        Try
            lstIllness.Items.Clear()
            cmd.Connection = myConn
            cmd.CommandText = "select ill from symptoms where sym = @symp"
            cmd.Parameters.AddWithValue("symp", lstSelected.Items)
            myReader = myCmd.ExecuteReader
            If (myReader.Read()) Then
                myReader.Close()
                myAdptr.SelectCommand = cmd
                myAdptr.Fill(dt)
                lstIllness.DisplayMember = "ill"
                lstIllness.ValueMember = "ill"
 
                For Each row As DataRow In dt.Rows
                    lstIllness.Items.Add(row("ill"))
                Next
                Dim builder As New StringBuilder()
                builder.Append("select distinct ill from symptoms where ")
                For y As Integer = 0 To lstSelected.Items.Count - 1
                    Dim parameterName As String = "@symp" & y.ToString()
                    If y <> 0 Then
                        builder.Append("and ")
                    End If
                    builder.Append(parameterName)
                    builder.Append(" in (select sym from symptoms where ill = i.ill) ")
                    cmd.Parameters.AddWithValue(parameterName, lstSelected.Items(y))
                Next
                cmd.CommandText = builder.ToString()
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        cmd = Nothing
        myReader = Nothing
        myConn.Close()
        Call Disconnect()

It has no error but when I click the diagnose button, nothing is happening. Please, can anybody tell me the problem with my code? I really need to finish this today, please help me. Thanks in advance, God bless

Viewing all articles
Browse latest Browse all 27355

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>