Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15567

VS 2019 [RESOLVED] MySQL Populate 2nd Dropdown

$
0
0
Having issues populating 2nd dropdown after first is selected. Not having issue populating first box issue is happening after choosing selection to populate 2nd

Code:

Imports MySql.Data.MySqlClient
Public Class Request
    Public conn As New MySqlConnection("server=localhost; user=root; password=mysql; database=xmas;")
    Dim str As String
    Private Sub Request_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        conn.Open()
        Try
            str = "SELECT `title` FROM `songlist` group by `title` order by `title` asc"
            Dim da As New MySqlDataAdapter(str, conn)
            Dim dt As New DataTable
            da.Fill(dt)
            If dt.Rows.Count > 0 Then
                ComboBox1.DataSource = dt
                ComboBox1.DisplayMember = "title"
                ComboBox1.ValueMember = "title"
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        conn.Close()
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        conn.Open()
        Try
            str = "SELECT `artist` FROM `songlist` where 'title' = `" & ComboBox1.SelectedItem & "`"
            Dim da As New MySqlDataAdapter(str, conn)
            Dim dt As New DataTable
            da.Fill(dt)
            If dt.Rows.Count > 0 Then
                ComboBox2.DataSource = dt
                ComboBox2.DisplayMember = "artist"
                ComboBox2.ValueMember = "artist"
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        conn.Close()
    End Sub
End Class


Viewing all articles
Browse latest Browse all 15567

Trending Articles



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