请大家看看我这段代码有什么问题!
Imports System.Data.OleDbPublic Class database
Implements IDisposable
Private myconn As System.Data.OleDb.OleDbConnection
Public Shared mystr As String = "provider=microsoft.jet.oledb.4.0;data source=D:\yyjxc.mdb;Database Password='""'; "
Private disposedValue As Boolean = False ' 检测冗余的调用
' IDisposable
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not Me.disposedValue Then
If disposing <> True Then
' TODO: 显式调用时释放非托管资源
Return
End If
' TODO: 释放共享的非托管资源
If myconn Is Nothing = False Then
myconn.Dispose()
myconn = Nothing
End If
End If
Me.disposedValue = True
End Sub
#Region " IDisposable Support "
' Visual Basic 添加此代码是为了正确实现可处置模式。
Public Sub Dispose() Implements IDisposable.Dispose
' 不要更改此代码。请将清理代码放入上面的 Dispose(ByVal disposing As Boolean) 中。
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
#End Region
Public Sub open()
If myconn Is Nothing = True Then
'建立数据库连接对象
myconn.ConnectionString = mystr
'打开连接
myconn.Open()
End If
End Sub
Public Sub close()
'如果数据库对象不为空则关闭数据库连接
If myconn Is Nothing = False Then
myconn.Close()
End If
End Sub
Public Function RunSelectSQL(ByVal sSQLString As System.String) As DataView
Me.open()
Dim myDS As DataSet = New DataSet
Dim myDA As OleDbDataAdapter = New OleDbDataAdapter(sSQLString, Me.myconn)
myDA.Fill(myDS)
Return myDS.Tables(0).DefaultView
End Function
Public Sub RunDelOrInsSQL(ByVal sSQLString As System.String)
Me.open()
Dim mycomm As OleDbCommand = New OleDbCommand(sSQLString, Me.myconn)
mycomm.ExecuteNonQuery()
End Sub
End Class