A little tip or help would be very much appreciated, please and thank you.
I have a DataBound ComboBox from my MySql table named "formmaintenance" which has 3 columns namely FormCode, FormName, FormDescription, Combobox DisplayMember is FormCode and ValueMember is FormCode as well, I have 2 TextBoxes named as txtName and txtDesc.
What I would like to happen is when I select an item in Combobox (ex: form101) I want to display the value of FormName of selected item (ex name: Paper) on txtName and FormDescription on txtdesc.
I have yet to know how to start with this, since I’m really new with Vb.Net.
Here is my Code(Updated)
If conn.State = ConnectionState.Closed Then
conn.ConnectionString = "Server = localhost; Username= root; Password =; Database =forms"
Try
conn.Open()
MsgBox("Connection Established")
Dim dt As New DataTable
Dim sql = "SELECT FormName FROM formma WHERE FormCode = '" & cmbCode.Text & "';"
Dim Result As String
cmd.Connection = conn
cmd.CommandText = sql
Result = cmd.ExecuteScalar()
da.SelectCommand = cmd
dr = cmd.ExecuteReader()
If Result IsNot Nothing Then
txtName.Text = Result.ToString()
End If
Catch ex As MySqlException
Console.WriteLine("Error: " & ex.ToString())
End Try
End If
End Sub
If I understand your question correctly, here’s the tip.
1- Load data from DB and bind it to the combobox:
2- On SelectedIndex_Changed event handler of cmbCode combobox, set text based on selected item of the combobox.
HTH.