注册 登录
编程论坛 VB.NET论坛

请大家看看我这段代码有什么问题!

yuzj064 发布于 2007-12-18 16:40, 1036 次点击
Imports System.Data.OleDb
Public 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
6 回复
#2
fairy42007-12-18 17:33

真不知道怎么想的!你代碼出現什么問題,你可以提出來,讓人家幫你看代碼!以為別人都閑的沒事情做嗎?
我給你段代碼,你幫我看看有什么問題!!!!!!!
#3
yuzj0642007-12-18 17:49
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
#4
fairy42007-12-18 18:43
myDA.Fill(myDS,"datalist") '臨時表,不一定要實際存在的表
#5
yuzj0642007-12-19 08:53
我用的是vs2005
有的在2003里还好好的
被移到2005里就出了很多毛病!
请大家帮忙看看我这段的毛病
附图一张。
#6
bygg2007-12-19 10:21
你的 myconn 只是定义一下,根本就是个NULL的.你想怎么用??
#7
fairy42007-12-19 13:16
1