我正在嘗試制作一個連接到資料庫的 VB.net WinForm 應用程式。
我有一個帶有規范的類來建立資料庫連接(Intersystems Cache)。資料庫不重要,原則重要。
如何從 FrmMain 中呼叫此類中的方法?我無法理解它。
謝謝
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
uj5u.com熱心網友回復:
如果你想創建一個型別的物件Connection,那么你可以這樣做:
Dim Connection1 As Connection = New Connection()
并呼叫它的方法DoOpenConnectionCache
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/446818.html
上一篇:TypeScript(Nodejs錯誤)型別'字串|undefined'不能分配給型別'string'。型別“未定義”不可分配給型別“字串”
