数据库具有数据,但是读取器读取"Has Row = False". [英] Database has data but reader read "Has Row=False"

查看:151
本文介绍了数据库具有数据,但是读取器读取"Has Row = False".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在Ms Access中有数据(1个数据),但是当ExecuteReader时,它不显示任何行.为什么?有什么建议吗?下面是我的代码.连接成功打开.

Hi all,

I have data in Ms Access (1 data) but when ExecuteReader, it show no row. Why? Any recommendation? Below is my code. Connection successfully open.

Public Function GetUserProfile(ByVal strSQL As String) As Boolean
    Dim cmd As New OleDbCommand
    Dim rdr As OleDbDataReader = Nothing
    Dim strErrMsg As String

    Try
        cmd.CommandText = strSQL
        cmd.CommandType = CommandType.Text
        cmd.Connection = MyBase.cnDB
        rdr = cmd.ExecuteReader 'At this point, it give no row in DB
        If rdr.HasRows Then
            While rdr.Read
                With CurrUser
                    If Not IsDBNull("ysnCollection") Then
                        .bCollection = (rdr("ysnCollection"))
                    Else
                        .bCollection = False
                    End If

                    If Not IsDBNull("ysnMaintenance") Then
                        .bMaintenance = (rdr("ysnMaintenance"))
                    Else
                        .bMaintenance = False
                    End If

                    If Not IsDBNull("ysnSecurity") Then
                        .bSecurity = (rdr("ysnSecurity"))
                    Else
                        .bSecurity = False
                    End If

                    If Not IsDBNull("ysnReport") Then
                        .bReport = (rdr("ysnReport"))
                    Else
                        .bReport = False
                    End If
                    Return True
                End With
            End While
        End If
    Catch ex As Exception
        strErrMsg = "Error in getting User Profile. " & MyBase.DBPath
        strErrMsg = strErrMsg & ControlChars.NewLine & ex.Message
        MsgBox(strErrMsg, MsgBoxStyle.Exclamation, strTitle)
        Return False
    End Try
End Function

推荐答案

取决于您作为strSQL传递给方法的字符串-如果它访问错误的表或包含WHERE子句,则为ExecuteReader可以合法地不返回任何行.使用调试器-在teh方法的first语句上放置一个断点,查看变量内容,然后逐步执行.这应该很明显.
Depends on the string you pass into the method as strSQL - if it accesses the wrong table, or contains a WHERE clause, the ExecuteReader could legitimately return no rows. Use the debugger - put a breakpoint on teh first statement in teh method, look at your variable contents, and step through. It should be pretty obvious.


这篇关于数据库具有数据,但是读取器读取"Has Row = False".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆