VB.net OOP 如何从 FrmMain 调用命名空间中的方法
VB.net OOP How to call method in namespace from FrmMain
我正在尝试创建一个连接到数据库的 VB.net WinForm 应用程序。
我有一个 class 的规范,用于建立数据库连接(系统间缓存)。数据库不重要,原理重要
如何从 FrmMain 中调用此 class 中的方法?
我无法理解它。
谢谢
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
和:
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
如果你想创建一个Connection
类型的对象,那么你可以这样做:
Dim Connection1 As Connection = New Connection()
并调用它的方法DoOpenConnectionCache
我正在尝试创建一个连接到数据库的 VB.net WinForm 应用程序。
我有一个 class 的规范,用于建立数据库连接(系统间缓存)。数据库不重要,原理重要
如何从 FrmMain 中调用此 class 中的方法? 我无法理解它。
谢谢
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
和:
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
如果你想创建一个Connection
类型的对象,那么你可以这样做:
Dim Connection1 As Connection = New Connection()
并调用它的方法DoOpenConnectionCache