|
-
Oct 17th, 2006, 02:16 AM
#1
Thread Starter
Hyperactive Member
[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:
Dim squery As String, sQuery1 As String, sString As String
Dim iCount As Integer, jCount As Integer
'Add column headers base on user selection
For iCount = 1 To lv2.ListItems.Count
sString = sString + "," + lv2.ListItems.Item(iCount)
Set iCol3 = lv3.ColumnHeaders.Add(, , lv2.ListItems.Item(iCount))
Next iCount
'Create a query record
squery = "SELECT " & Mid(sString, 2, Len(sString)) & " FROM MAKLUMAT_RAWATAN "
If cboFields = "Age" Then
sQuery1 = "WHERE " & cboFields & " " & cboOperator & "" & txtSearch
Else
sQuery1 = "WHERE " & cboFields & " " & cboOperator & "'" & txtSearch & "'"
End If
'Test if user use filtering or not
If cboFields = "" Or cboOperator = "" Or txtSearch = "" Then
squery = squery + sQuery1
Else
squery = squery
End If
RS.Open squery, con, adOpenDynamic, adLockOptimistic
'Add Records (I Got problem here... How can I the query here?)
For iCount = 0 To RS.RecordCount - 1
Set iItem3 = lv3.ListItems.Add(, , RS(0)) 'Id
'Add subitems
For jCount = 1 To lv2.ListItems.Count - 1
iItem3.ListSubItems.Add , , RS(jCount)
Next jCount
RS.MoveNext
Next iCount
As you can see the 'Add Records section, I have problem to use the sql query to populate listview3. Can anybody help
-
Oct 17th, 2006, 02:36 AM
#2
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|