Click here to Skip to main content
13,087,797 members (81,751 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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
            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"))
                            .bCollection = False
                        End If
                        If Not IsDBNull("ysnMaintenance") Then
                            .bMaintenance = (rdr("ysnMaintenance"))
                            .bMaintenance = False
                        End If
                        If Not IsDBNull("ysnSecurity") Then
                            .bSecurity = (rdr("ysnSecurity"))
                            .bSecurity = False
                        End If
                        If Not IsDBNull("ysnReport") Then
                            .bReport = (rdr("ysnReport"))
                            .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
Posted 29-Nov-12 21:11pm
Krunal R 30-Nov-12 3:13am
put a breakpoint at rdr = cmd.ExecuteReader and debug it
Luiey Ichigo 30-Nov-12 3:56am
already done before I post this question. I have no idea why it doesn't read that in the database has value.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170813.1 | Last Updated 30 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100