Results 1 to 6 of 6

Thread: do while loop

  1. #1

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

    do while loop

    I only want to place the first three records in my comboBox, but this code places all the records in there:

    Code:
     
    Do While objDR.Read = True
                    Me.cmbCards.Items.Add(Trim(objDR("employee_first_name")) 
    loop
    so, I changed the code to:

    Code:
     
    Do While counter < 2
                    Me.cmbCards.Items.Add(Trim(objDR("employee_first_name")) 
    counter = counter + 1
                Loop
    but this returned an err msg....no data found...anyone have the proper syntax to do this?

    thanks
    It's tough being an unhandled exception...

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

  2. #2
    Addicted Member VB6Coder's Avatar
    Join Date
    Apr 2001
    Location
    Northampton, UK
    Posts
    185
    I think the reason why it is falling over is because you are not calling the objDR.Read method in the second example while you are looping round

    Try:
    Code:
    Do While counter < 2 and objDR.Read
                    Me.cmbCards.Items.Add(Trim(objDR("employee_first_name")) 
    counter = counter + 1
                Loop

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Why not just use TOP 3 in your SQL Query.

  4. #4

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    thanks VBCoder...Edneeis...theres a TOP command is SQL? Do you have a example?
    It's tough being an unhandled exception...

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

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    SELECT TOP 3 * FROM MyTable

  6. #6

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    did not know that...thanks
    It's tough being an unhandled exception...

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

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