首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

OleDbDataReader可否作为函数的返回值

2013-07-09 
OleDbDataReader能否作为函数的返回值Dim rd As OleDb.OleDbDataReader OutLine.DisplayAllOutline(AUT

OleDbDataReader能否作为函数的返回值


Dim rd As OleDb.OleDbDataReader = OutLine.DisplayAllOutline("AUTO_CODE", True)
‘这一句调用下面的函数时,说OleDbDataReader已关闭,本人菜鸟,不明白是怎么回事,rd要先打开?

Public Shared Function DisplayAllOutline(ByRef sub_str_OrderByColume As String, Optional ByRef sub_IsReversed As Boolean = False) As OleDb.OleDbDataReader
        Dim str_sql As New System.Text.StringBuilder
        str_sql.Append("SELECT * FROM OUTLINE ORDER BY ")
        str_sql.Append(sub_str_OrderByColume)
        If sub_IsReversed = True Then
            str_sql.Append(" DESC")
        End If

        Try
            Using conn As New OleDb.OleDbConnection(g_str_DbConStr)
                conn.Open()
                Using comm As New OleDb.OleDbCommand
                    comm.Connection = conn
                    comm.CommandText = str_sql.ToString
                    Dim read As OleDb.OleDbDataReader = comm.ExecuteReader
                    Return read
                End Using
            End Using
        Catch ex2 As Exception
            MsgBox(ex2.ToString())
        End Try

        'Dim read As OleDb.OleDbDataReader = DbManager.GetResult(str_sql.ToString)
        'Return read
    End Function


[解决办法]
用了using导致的 过了using 就销毁了

热点排行