469,346 Members | 6,467 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,346 developers. It's quick & easy.

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??

Expand|Select|Wrap|Line Numbers
  1. Call Connection
  2. Set inv = New ADODB.Recordset
  3.  
  4. inv.Open "SELECT * FROM Invoice_Trans WHERE Inv_No=" & Val(txtInvNo.Text) & "", con, 3, 3
  5.  
  6. lstSrno.AddItem (inv!SrNo)
  7. lstProd.AddItem (inv!Prod_Code)
  8. lstQty.AddItem (inv!Qty)
  9. lstAmt.AddItem (inv!amount)
  10.  
  11. rs.Close
  12.  
Feb 7 '08 #1
4 2419
werks
220 100+
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.Text) & "", 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:

Expand|Select|Wrap|Line Numbers
  1. Dim Ctrlst As Integer
  2. Dim TmpValue As String
  3.  
  4.   While Not adoUser.EOF
  5.         Ctrlst = Ctrlst + 1
  6.             lstLibrarian.ListItems.Add , , adoUser.Fields("BorrowerID")
  7.         For j = 1 To 6     'NUMBER OF COLUMNS IN THE LISTBOX
  8.             TmpValue = ""     'TEMPORARY STORAGE
  9.             If Not adoUser.Fields(j) = "" Then
  10.                 TmpValue = adoUser.Fields(j)
  11.             End If
  12.             lstLibrarian.ListItems(Ctrlst).ListSubItems.Add , , TmpValue
  13.         Next
  14.         adoUser.MoveNext
  15.     Wend
  16.  

Better Than Yesterday ^^
Feb 7 '08 #2
mafaisal
142 100+
Hello,

Try This

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

like this

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.Text) & "", con, 3, 3

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

rs.Close
Feb 7 '08 #3
werks
220 100+
try looping it upto the last record...
Feb 7 '08 #4
debasisdas
8,127 Expert 4TB
try like this

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. Dim sql As String
  3. lstcompany.Clear
  4. sql = "SELECT companyname from company"
  5. RsComp.Open sql, Con, adOpenDynamic, adLockOptimistic
  6. Set lstcompany.DataSource = RsComp
  7.  
  8. For i = 0 To RsComp.RecordCount - 1
  9. lstcompany.AddItem RsComp(0)
  10. RsComp.MoveNext
  11. Next i
  12. RsComp.Close
  13.  
  14.  
  15. End Sub
  16.  
  17.  
Feb 8 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by deebeetwo | last post: by
4 posts views Thread by db2admin | last post: by
7 posts views Thread by Frank Swarbrick | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.