Results 1 to 2 of 2

Thread: add item from database into listview..help me pls!!

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    11

    add item from database into listview..help me pls!!

    hello guys out there..i'm new in VB and need your helping to solve this problem...

    now i have select all the data from database using sql command..
    but i dunno how to add into listview..

    i'm only know this coding....but it can't used

    Dim itm As ListItem

    Set itm = ListView1.ListItems.Add(, , stritemvalue)
    itm.SubItems(1) = strItemdescription

    so please help me..thanks a lot...

  2. #2
    Junior Member
    Join Date
    May 2004
    Location
    Brisbane - Australia
    Posts
    23
    Are you using ADO or DAO with your SQL statement.

    You can loop through the records in a recordset and add them to the listbox

    Here is how I have done it with an ADO connection before

    Code:
    Dim cnt As ADODB.Connection
    Dim rst As ADODB.Recordset
    
    Set cnt = New ADODB.Connection
    Set rst = New ADODB.Recordset
    
    ' set up connections
    With cnt
        .ConnectionString = strConnectionString
        .Open
    End With
    
    With rst
        .Source = strSQL
        .ActiveConnection = cnt
        .Open
        Do Until .EOF
            ListBox1.AddItem (.Fields("WHATEVER_FIELD"))
            .MoveNext
        Loop
        .Close
    End With
    Set rst = Nothing
    
    cnt.Close
    Set cnt = Nothing
    Hope this helps

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