I am trying to get my combo box to refresh and have new values(name) automatically whenever the user adds new data to the database from a separate form (LoanForm).
Goal: The ComboxBox should reflect new names after adding new data from LoanForm. Screenshot: https://snipboard.io/CjBTAN.jpg
Screenshot LoanForm: https://snipboard.io/2HdkIt.jpg
(LoanForm adding data works perfectly)
What I have tried:
I wrote a code that makes the comboBox reflect values after adding from another form, so when I navigate to "collections form" and search their name it should reflect: Screenshot: https://snipboard.io/AMcr3V.jpg
The code for ComboBox:
Private Sub ComboBox1_Click(sender As Object, e As EventArgs) Handles ComboBox1.Click
MysqlConn = New MySqlConnection
MysqlConn.ConnectionString = "server=localhost;userid=root;password=root;database=golden_star"
Dim da As New MySqlDataAdapter
Dim dt As New DataTable
Dim query As String
MysqlConn.Open()
query = "select * from loan"
Command = New MySqlCommand(query, MysqlConn)
da.SelectCommand = Command
da.Fill(dt)
ComboBox1.DataSource = dt
ComboBox1.DisplayMember = "account_name"
MysqlConn.Close()
End Sub
But the code to refresh new values doesn't work until I run the program which I don't want that.
I have another code that allows users to bind data from comboBox to textbox according to name selection but if I do input the above code for refresh values the binding of data to textbox doesn't work. Two of them don't work unless I remove one of them. Can anyone assist me with what went wrong?
Thank you.