Fetch Multiple Records

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mclueless
    New Member
    • Jan 2008
    • 56

    Fetch Multiple Records

    I am working with VB6 and Access. There is a SQL query I have written to retrieve a few records. But when I try to display these records in a listbox, only the first one is fetched, others are not. What should I do to fetch all??

    [CODE=vb]
    Call Connection
    Set inv = New ADODB.Recordset

    inv.Open "SELECT * FROM Invoice_Trans WHERE Inv_No=" & Val(txtInvNo.Te xt) & "", con, 3, 3

    lstSrno.AddItem (inv!SrNo)
    lstProd.AddItem (inv!Prod_Code)
    lstQty.AddItem (inv!Qty)
    lstAmt.AddItem (inv!amount)

    rs.Close
    [/CODE]
    Last edited by Killer42; Feb 8 '08, 01:07 AM. Reason: Added CODE=vb tag
  • werks
    New Member
    • Dec 2007
    • 218

    #2
    Originally posted by mclueless
    I am working with VB6 and Access. There is a SQL query i have written to retrieve few records. but when i try to display these records in a listbox, only the first one is fetched, others are not. What should i do to fetch all??


    Call Connection
    Set inv = New ADODB.Recordset

    inv.Open "SELECT * FROM Invoice_Trans WHERE Inv_No=" & Val(txtInvNo.Te xt) & "", con, 3, 3

    lstSrno.AddItem (inv!SrNo)
    lstProd.AddItem (inv!Prod_Code)
    lstQty.AddItem (inv!Qty)
    lstAmt.AddItem (inv!amount)

    rs.Close

    this is my code on viewing records from the DB:

    [CODE=vb]
    Dim Ctrlst As Integer
    Dim TmpValue As String

    While Not adoUser.EOF
    Ctrlst = Ctrlst + 1
    lstLibrarian.Li stItems.Add , , adoUser.Fields( "BorrowerID ")
    For j = 1 To 6 'NUMBER OF COLUMNS IN THE LISTBOX
    TmpValue = "" 'TEMPORARY STORAGE
    If Not adoUser.Fields( j) = "" Then
    TmpValue = adoUser.Fields( j)
    End If
    lstLibrarian.Li stItems(Ctrlst) .ListSubItems.A dd , , TmpValue
    Next
    adoUser.MoveNex t
    Wend
    [/CODE]


    Better Than Yesterday ^^

    Comment

    • mafaisal
      New Member
      • Sep 2007
      • 142

      #3
      Hello,

      Try This

      Set Item = lvwRoom.ListIte ms.Add(, , inv!SrNo)
      Item.SubItems(1 ) = inv!Prod_Code
      Item.SubItems(2 ) = inv!Qty

      like this

      Originally posted by mclueless
      I am working with VB6 and Access. There is a SQL query i have written to retrieve few records. but when i try to display these records in a listbox, only the first one is fetched, others are not. What should i do to fetch all??


      Call Connection
      Set inv = New ADODB.Recordset

      inv.Open "SELECT * FROM Invoice_Trans WHERE Inv_No=" & Val(txtInvNo.Te xt) & "", con, 3, 3

      lstSrno.AddItem (inv!SrNo)
      lstProd.AddItem (inv!Prod_Code)
      lstQty.AddItem (inv!Qty)
      lstAmt.AddItem (inv!amount)

      rs.Close

      Comment

      • werks
        New Member
        • Dec 2007
        • 218

        #4
        try looping it upto the last record...

        Comment

        • debasisdas
          Recognized Expert Expert
          • Dec 2006
          • 8119

          #5
          try like this

          [code=vb]
          Private Sub Form_Load()
          Dim sql As String
          lstcompany.Clea r
          sql = "SELECT companyname from company"
          RsComp.Open sql, Con, adOpenDynamic, adLockOptimisti c
          Set lstcompany.Data Source = RsComp

          For i = 0 To RsComp.RecordCo unt - 1
          lstcompany.AddI tem RsComp(0)
          RsComp.MoveNext
          Next i
          RsComp.Close


          End Sub

          [/code]

          Comment

          Working...