Akira
Akira

Reputation: 5

Database values in textbox if select Combobox vb.net mysql

i cant figure out my problem there is no error but value in combobox not showing from mysqldatabase here is my code

    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Dim conn As New MySqlConnection

    conn.ConnectionString = "server=localhost;user vbid=root;password=admin;database=dnidb"

    Dim reader As MySqlDataReader

    Try
        conn.Open()
        Dim query As String
        query = "select * from dnidb.hargapro where NamaP = '" & ComboBox1.Text & "'"
        command = New MySqlCommand(query, conn)
        reader = command.ExecuteReader
        While reader.Read
            TextBox8.Text = reader.GetInt32("HargaP")
          End While
        conn.Close()
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    Finally
        conn.Dispose()
    End Try


End Sub

this code was no error, but didnt show anything in the combobox, i try to make this cone on combobox_selectedindexchanges and same thing nothing showing up in the combobox

i just follow the code from here https://www.youtube.com/watch?v=HfnoGEmRGvc

Upvotes: 1

Views: 720

Answers (1)

willa_012
willa_012

Reputation: 46

I don't see any code that tries to retrieve the product names to combobox, and it seems like the above code should be on SelectedIndexChanged event of the combobox.

Upvotes: 1

Related Questions