Using a Single Connection across forms

  • Thread starter Thread starter Chester Grice
  • Start date Start date
C

Chester Grice

I need to know how, if possible, to use one connection on several
different forms as well as reusing data adapter from another form. it
seems wasteful to keep adding connector and adapters to every form.
VB.Net 2003. Will a module be helpful, if so, how
 
Hi ,
The way you would do that is using what is called a Singleton pattern.
This is an object oriented desing patter. The idea is that you will always
have only one instance of your class and it can be shared among any class.
Here is an example

Public Class Singleton
Private Shared instance As Singleton
Public Shared Function getInstance() As Singleton
If (instance Is Nothing) Then
instance = New Singleton
Return instance
End If
Return instance
End Function
Public Sub HelloWorld()
MsgBox("Hello World")
End Sub
End Class


You can call methods as follows

Singleton.getInstance().HelloWorld

So you can modify the above class to have a single dataset and then
basically use it in any other class you want.

I hope this helps.


Anand Balasubramanian
Microsoft, Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks
 
Create class with public static connection variable to share connection.
I guess you are talking about a data adapter placed on a form (not defined
from code).
Change its Modifiers property to public or protected to make visibility to
other forms
-Praveen
 
Back
Top