I have two forms that access the same database, the second form adds new records to the table while the first form reads from it.
When I add a new record in the second form and I press OK, I am returned to the first form, my problem is that the first form does not show the newly added record, I have to close the entire program and re-load it in order to see the changes.
I'm wondering if there's a way once I add a new record to update the bindingsource in the first form to reflect the new changes.
the following is the code I use in the first form to read from the table
Dim prjData As ClientsAccessDim prjDataset As nclMisDataSetDim WithEvents prjBindingSource As BindingSourcePrivate Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load prjData = New ClientsAccess prjDataset = prjData.getPrjAccessDataSet prjBindingSource = New BindingSource With prjBindingSource .DataSource = prjDataset .DataMember = "projets" End With
You're saying I should add the module to the class "ClientsAccess" instead of directly on the form?
Then how I can access it from the forms?
lojk
OK well it wasn't explained what ClientsAccess was but my comment still stands. If ClientsAccess is some kind of database access class then it very much makes sense to put the DS inside that and put an instance of the ClientsAccess in a global module.
You need to increase the scope of the dataset variable if you want to share it between 2 forms (you can do this , i have previously bound one dataset instance full of lookups that was loaded at application startup and stored in a Shared Class to 10s of forms in one application, it was actually pushed into each form but the principal is the same if you want to pull it like you are above). The benefit to this approach was that even if the lookups were changed by a database read/write somewhere else - EVERY form that was bound to the Lookup DS automatically updated itself.
Where you actually put it is up to you but by creating a fresh instance in every instance of the form they are obviously unrelated to each other.
FCapo
ASKER
I'm having a tough time configuring it this way, I'm sorry for this inconvenience.
I have a public class I use to access my database :
Public Class ClientsAccess Private prjAccessTableAdapter As nclMisDataSetTableAdapters.projetsTableAdapter Private prjDataset As nclMisDataSet Private prjDataTable As DataTable Public Function getPrjAccessDataSet() As nclMisDataSet Try prjAccessTableAdapter = New nclMisDataSetTableAdapters.projetsTableAdapter prjDataset = New nclMisDataSet prjAccessTableAdapter.Fill(prjDataset.projets) Return prjDataset Catch ex As Exception Throw ex End Try End FunctionEnd Class
And from my forms, I load the dataset in this way :
Dim prjData As ClientsAccessDim prjDataset As nclMisDataSetDim WithEvents prjBindingSource As BindingSourcePrivate Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load prjData = New ClientsAccess prjDataset = prjData.getPrjAccessDataSet prjBindingSource = New BindingSource With prjBindingSource .DataSource = prjDataset .DataMember = "projets" End With
Basically both forms have the above code, how exactly can I implement the modules in this situation without having to completely change the code. This method is very new to me and so I would appreciate as much detail as possible.
Then how I can access it from the forms?