Results 1 to 4 of 4

Thread: data reader question

  1. #1

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075

    data reader question

    if the query below returns zero rows, then shouldn't the objDR.read = false? The reason I ask this is becasue I know that no rows are being returned but it still goes into the Do while loop?




    VB Code:
    1. sqlCmd = "select employee_last_name,employee_first_name,employee_id from pcms.pcms_pcard where employee_work_unit='" & CmbWorkUnit.Text & "' and status_ind='A' order by employee_last_name"
    2.         Dim objCom As New OleDbCommand(sqlCmd, objCon)
    3.         Try
    4.  
    5.             objCon.Open()
    6.             objDR = objCom.ExecuteReader
    7.             Do While objDR.Read = True
    8.                 Me.CmbCards.Items.Add(Trim(objDR("employee_first_name")) & " " & (Trim(objDR("employee_last_name")) & "  " & (Trim(objDR("employee_id")))))
    9.             Loop
    10.             objDR.Close()
    11.         Catch ex As Exception
    12.             MsgBox("Credit Card fill error: " & Err.Description)
    13.         Finally
    14.             objCon.Close()
    15.         End Try
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    You might think so. Try using the HasRows property of the datareader if you're using framework 1.1
    MSDN
    I know an empty Access db still shows row 1, even though there's nothing in it. Maybe that's the problem.

  3. #3

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    it's an Oracle DB
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  4. #4
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Well, the link at MSDN has a section on Oracle, not sure if it'll help you. But one example there runs similar code to yours using HasRows
    VB Code:
    1. If myReader.HasRows Then
    2.   Do While myReader.Read()
    3.     Console.WriteLine(vbTab & "{0}" & vbTab & "{1}", myReader.GetInt32(0), myReader.GetString(1))
    4.   Loop
    5. Else
    6.   Console.WriteLine("No rows returned.")
    7. End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width