I am trying to make a VB.net WinForm-application that connects to a database.
I have a class with the specs to make a database-connection (Intersystems Cache). The database isn't important, the principile does.
How do I call the methods in this class form the FrmMain? I can't get my head around it.
Thanks
Imports Test.NSConnection.Connection
Public Class FrmMain
Private Sub FrmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'how do I call the DoOpenConnectionCache?
End Sub
End Class
and:
Imports InterSystems.Data.CacheClient
Imports InterSystems.Data.CacheTypes
Imports System
Imports System.Data
Namespace NSConnection
Public Class Connection
Private _cacheString As String
Public Property cacheString() As String
Get
Return _cacheString
End Get
Set(ByVal value As String)
_cacheString = value
End Set
End Property
Private _cnCache As CacheADOConnection
Public Property cnCache() As CacheADOConnection
Get
Return _cnCache
End Get
Set(ByVal value As CacheADOConnection)
_cnCache = value
End Set
End Property
Private Sub SetConnectionString()
Dim _cacheString As String = "Server = localhost; Port = ****; Namespace = ****; User ID= **** ; Password= ****;"
Dim _cnCache = New CacheConnection(_cacheString)
End Sub
Public Sub DoOpenConnectionCache()
Try
If _cnCache.State = ConnectionState.Closed Then
_cnCache.Open()
End If
Catch ex As Exception
MessageBox.Show("Error" & vbCrLf & ex.Message)
End Try
End Sub
Public Sub DoCloseConnectionCache()
Try
If _cnCache.State = ConnectionState.Open Then
_cnCache.Close()
End If
Catch ex As Exception
MessageBox.Show("Error" & vbCrLf & ex.Message)
End Try
End Sub
End Class
End Namespace
CodePudding user response:
If you want to create an object of type Connection
, then you can do it like this:
Dim Connection1 As Connection = New Connection()
and call its method DoOpenConnectionCache