Results 1 to 3 of 3

Thread: ado and listboxes???

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    9

    ado and listboxes???

    I am using vb6 and sql server 2000.
    I am trying to put results from a query into a listbox when the form loads.

    Here is my code:

    I need to link the query results to listbox1.text???

    Dim emplRS As New Adodb.Recordset

    ' sets the connection
    Const connectStr = "Provider=SQLOLEDB.1;Data Source=MA0;database=ma00_app;uid=gsha;pwd=15;"

    ' set property to automatically create a connection
    emplRS.ActiveConnection = connectStr

    ' open recordset with query for all records matching variable

    emplRS.Open "select whsekey From timwarehouse where companyid = 'QCC' and whseid = '380'"

    empirs.Close

    my brain is not working, how do i link the query results to listbox1.text?

    Thanks

  2. #2
    New Member George W Bush's Avatar
    Join Date
    Oct 2002
    Location
    Eating Pretzels in the Oval Office
    Posts
    14
    VB Code:
    1. Dim emplRS As New Adodb.Recordset
    2.  
    3. ' sets the connection
    4. Const connectStr = "Provider=SQLOLEDB.1;Data Source=MA0;database=ma00_app;uid=gsha;pwd=15;"
    5.  
    6. ' set property to automatically create a connection
    7. emplRS.ActiveConnection = connectStr
    8.  
    9. ' open recordset with query for all records matching variable
    10.  
    11. emplRS.Open "select whsekey From timwarehouse where companyid = 'QCC' and whseid = '380'"
    12.  
    13. do while not emplRs.bof AND emplRs.eof
    14.  
    15. listbox1.additem emplRs.fields("nameoffield").value
    16. emplRs.movenext
    17.  
    18. loop
    19.  
    20. emplRs.close
    "For NASA, space is still a high priority"
    -Me

    "We're going to have the best educated American people in the world."
    -Me!

  3. #3
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    In between opening and closing the recordset, loop through the recordset and the items to the listbox.
    VB Code:
    1. emplRS.Open "select whsekey From timwarehouse where companyid = 'QCC' and whseid = '380'"
    2.  
    3. Do While Not emplRS.EOF
    4.     List1.AddItem emplRS!whsekey
    5.     emplRS.MoveNext
    6. Loop
    7.  
    8. empirs.Close

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