Hi everyone,
I've been trying to fix that issue for some times now and i need your help please.
Basically, i have 2 forms (form1 and form2). I have a set of textboxes on form1 that are bind on a dataset via a bindingsource. when form1 is loaded, all textboxes are filled in correctly. Now i want to update one textbox on form1 via form2. Basically form2 is just a simple form with one textbox and a button. The user is asked to put the value he wants in that textbox on form2 and when he clicked on the button, it saves the new value in the database - then form2 get closed and we are back into form1 (main form).
here is my code to do that :
and here is how my textbox in binded on form1 :
Everything works fine with the update. All I want to see now is that new value showing in form1 without having to close my app and open it again. I've tried the bindingsource.resetbinding method but did not work.
The only way I found which I believe is not the correct way is to directly change the form1.textbox.text = form2.textbox.text which shows the new value as I wanted but my bindingsource is still having in memory the old value.
Hope I was clear enough and thanks in advance for your help. :encouragement:
I've been trying to fix that issue for some times now and i need your help please.
Basically, i have 2 forms (form1 and form2). I have a set of textboxes on form1 that are bind on a dataset via a bindingsource. when form1 is loaded, all textboxes are filled in correctly. Now i want to update one textbox on form1 via form2. Basically form2 is just a simple form with one textbox and a button. The user is asked to put the value he wants in that textbox on form2 and when he clicked on the button, it saves the new value in the database - then form2 get closed and we are back into form1 (main form).
here is my code to do that :
VB.NET:
Private Sub btnUpdateKM_Click(sender As Object, e As EventArgs) Handles btnUpdateKM.Click
'open DB connection
Conn = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|dbServauto.mdb")
Conn.Open()
'start Transaction
Trans = Conn.BeginTransaction
Dim KM = tbKM.Text
Dim IDVehicule = tbVehiculeID.Text
'define a command for the sql statement
Cmd = New OleDb.OleDbCommand("update tblCars set KM= " & KM & " where ID=:0", Conn, Trans)
Cmd.Parameters.AddWithValue(":0", IDVehicule)
'execute the command
Cmd.ExecuteNonQuery()
'save the transaction
Trans.Commit()
'close the connection
Conn.Close()
'Form1.KMTextBox.Text = tbKM.Text
tbKM.Text = ""
Me.Close()
End Sub
VB.NET:
KMTextBox.DataBindings.Clear()
KMTextBox.DataBindings.Add(New Binding("text", bindingcar, "KM"))
Everything works fine with the update. All I want to see now is that new value showing in form1 without having to close my app and open it again. I've tried the bindingsource.resetbinding method but did not work.
The only way I found which I believe is not the correct way is to directly change the form1.textbox.text = form2.textbox.text which shows the new value as I wanted but my bindingsource is still having in memory the old value.
Hope I was clear enough and thanks in advance for your help. :encouragement: