Form not update from the database

ladivito

Member
Joined
Mar 9, 2015
Messages
8
Programming Experience
Beginner
Hi ,

I had 2 forms, Form A and Form B
Form A are to insert employee details
Form B retrieve employee details from database (insert from Form A)

The problem i had was, the Form B not able to retrieve the edited/updated data which has been done from Form A, it only retrieve old data(b4 edit/update)
* unless i close and run again then it running well

The code for Form B are as below ::::

:very_drunk::very_drunk::very_drunk::very_drunk: please help... Thanks
    Private Sub employeepayroll_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim i As Integer

        Timer1.Enabled = True
        pdatetextbox.Enabled = False
        eictextbox.Enabled = False

        dbProvider = "PROVIDER=Microsoft.ACE.OLEDB.12.0;"
        dbSource = "Data Source = |DataDirectory|\empdb.accdb"

        con.ConnectionString = dbProvider & dbSource

        con.Open()
        sql = "Select ename from tblemp order by ename"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "tblemp")

        For i = 0 To ds.Tables("tblemp").Rows.Count - 1
            enamecombo.Items.Add(ds.Tables("tblemp").Rows(i).Item("ename").ToString())
        Next

        con.Close()
    End Sub
 
Last edited by a moderator:
The issue should be fairly clear: you're only executing code to retrieve data in the Load event handler, so only when the form loads. If you want to do it after the form loads then you have to have code somewhere that will/can be executed after the form loads. The obvious choice is to put the code in a method that you can call from the Load event handler and elsewhere, e.g. the Tick event handler of a Timer or the Click event of a Button.
 
Hi,

i move the code to a button and when click on it the data that retrieve to the combobox still showing old/not updated data from the database.
 
I don't see you clearing old items in your code, you only add items.

It would make more sense to bind DataSource to this ComboBox, and use the same data source object as in your other form if you have that, or bind to DataTable here.
 
Back
Top