Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

VB
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
Posted
Comments
[no name] 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

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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900