public declarations

wilko18

Member
Joined
Feb 7, 2006
Messages
11
Programming Experience
Beginner
Im creating an application that will have several forms that all need to connect to a database.

How do I declare my connection object and connection string so that is is accessable from all forms? i.e. in a spearate module?
 
In a module, a class doesnt really matter. Only that if you use a class you will have to create an object of that class before you can use the methods

Inside a class called Class1

VB.NET:
Friend Function CreateConnection() as OleDbConnection
Dim MyConnection As New System.Data.OleDb.OleDbConnection
MyConnection.Connectionstring = Your Connection String
 
Return MyConnection
 
MyConnection.Dispose
End Function.

To use it from inside a class...

VB.NET:
Dim ThisConnection As OleDbConnection = Class1.CreateConnection

From inside a module it is near enough the same but you would jst omit the Class1
 
Back
Top