Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

BindingSource

Posted on 2012-03-12
4
Medium Priority
?
420 Views
Last Modified: 2012-03-12
Hello,

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 ClientsAccess
Dim prjDataset As nclMisDataSet
Dim WithEvents prjBindingSource As BindingSource

Private 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

Open in new window


Thank you,

Fred
0
Comment
Question by:FCapo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
lojk earned 1500 total points
ID: 37709896
This is all to do with the scope of your Dataset Variable - increase its scope by putting it in a module or Shared Class

Declare a Global Module

Public Module modGeneral

public prjData As new ClientsAccess()
public prjDataset As new nclMisDataSet()

End Module

and store your Dataset instance in there and then in your form(s)..


Dim WithEvents prjBindingSource As BindingSource

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

               prjBindingSource = New BindingSource

       With prjBindingSource
            .DataSource = modGeneral.prjDataset
            .DataMember = "projets"
        End With


Actually the operations you perform on that dataset should also go in the module/shared class rather than in the form.
0
 

Author Comment

by:FCapo
ID: 37709954
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?
0
 
LVL 9

Expert Comment

by:lojk
ID: 37710015
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.
0
 

Author Comment

by:FCapo
ID: 37710454
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 Function

End Class

Open in new window


And from my forms, I load the dataset in this way :
Dim prjData As ClientsAccess
Dim prjDataset As nclMisDataSet
Dim WithEvents prjBindingSource As BindingSource

Private 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

Open in new window

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.

Thank you
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question