Click here to Skip to main content
11,571,471 members (75,937 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET MS-Access
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
Posted 29-Nov-12 21:11pm
Comments
Krunal R at 30-Nov-12 3:13am
   
put a breakpoint at rdr = cmd.ExecuteReader and debug it
Luiey Ichigo at 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
good
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.
  Permalink  

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

  Print Answers RSS


Advertise | Privacy | Mobile
Web04 | 2.8.150624.2 | Last Updated 30 Nov 2012
Copyright © CodeProject, 1999-2015
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