Results 1 to 2 of 2

Thread: [RESOLVED] Need help to populate listview using sql

  1. #1

    Thread Starter
    Hyperactive Member Bearnerd's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    290

    Resolved [RESOLVED] Need help to populate listview using sql

    I use listview1 to display list of Fields name from a table. Now I add another listview2 to display fields name user select from listview1. I use listview1_doubleclick event to add item to listview2. Ok this part I done successfully.

    Now I add record filtering section on my form and add cboFields, cboOperator and txtSearch. These 3 controls needed to create the sql query. Ok now when user select field eg. ID, operator eg. < and type 10 into txtSearch I have a complete sql query as follow

    SELECT ID,NAME,ADDRESS FROM PATIENT WHERE ID < 10
    This is the code I use so far
    VB Code:
    1. Dim squery As String, sQuery1 As String, sString As String
    2.     Dim iCount As Integer, jCount As Integer
    3.    
    4.     'Add column headers base on user selection
    5.     For iCount = 1 To lv2.ListItems.Count
    6.         sString = sString + "," + lv2.ListItems.Item(iCount)
    7.         Set iCol3 = lv3.ColumnHeaders.Add(, , lv2.ListItems.Item(iCount))
    8.     Next iCount
    9.    
    10.     'Create a query record
    11.     squery = "SELECT " & Mid(sString, 2, Len(sString)) & " FROM MAKLUMAT_RAWATAN "
    12.     If cboFields = "Age" Then
    13.         sQuery1 = "WHERE " & cboFields & " " & cboOperator & "" & txtSearch
    14.     Else
    15.         sQuery1 = "WHERE " & cboFields & " " & cboOperator & "'" & txtSearch & "'"
    16.     End If
    17.    
    18.     'Test if user use filtering or not
    19.     If cboFields = "" Or cboOperator = "" Or txtSearch = "" Then
    20.         squery = squery + sQuery1
    21.     Else
    22.         squery = squery
    23.     End If
    24.     RS.Open squery, con, adOpenDynamic, adLockOptimistic
    25.    
    26.     'Add Records (I Got problem here... How can I the query here?)
    27.     For iCount = 0 To RS.RecordCount - 1
    28.         Set iItem3 = lv3.ListItems.Add(, , RS(0)) 'Id
    29.         'Add subitems
    30.         For jCount = 1 To lv2.ListItems.Count - 1
    31.             iItem3.ListSubItems.Add , , RS(jCount)
    32.         Next jCount
    33.         RS.MoveNext
    34.     Next iCount

    As you can see the 'Add Records section, I have problem to use the sql query to populate listview3. Can anybody help

  2. #2

    Thread Starter
    Hyperactive Member Bearnerd's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    290

    Re: Need help to populate listview using sql

    I really sorry, I just realise that I make a silly mistake in the query section. I can run my program successfully now. Sorry for this mistake.

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