Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15705

help , treeview and sql group by

$
0
0
hello
i want to show Ado recordset fields on Treeview
but 2 problems


field1- country / field2- city
Italy Rome
Italy Napoli
Italy Torino
France Paris
France Lyon
...

Europe (root)
I
ı_____ Italy
______I_____ Rome
___________ Napoli
___________ Torino
ı_____ France
______I_____ Paris
______ ____ Lyon

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim oCmd As ADODB.Command
Dim strCon As String
Dim strSql As String

Dim MyDataFile As String
Dim NameKey As String
Dim countryName As String
Dim cityKey As String
Dim cityName As String


MyDataFile = App.Path & "\DataFile" & "abc.mdb"
strCon = "Provider = Microsoft.Jet.OLEDB.4.0;data source=" & MyDataFile & ""

strSql = "SELECT * FROM COUNTRIES GROUP BY COUNTRY " --------------error cannot group selected with "*"
' or change it as select COUNTRY , MAX(CITY) AS CITY FROM COUNTRIES GROUP BY COUNTRY "

Set cn = New ADODB.Connection
cn.CursorLocation = adUseClient
cn.Open strCon

Set oCmd = New ADODB.Command
Set oCmd.ActiveConnection = cn
oCmd.CommandType = adCmdText

Set rs = New ADODB.Recordset
rs.Open strSql, cn, adOpenDynamic, adLockOptimistic

TreeView1.Nodes.Clear
TreeView1.LineStyle = tvwRootLines

TreeView1.ImageList = ImageList1


TreeView1.Nodes.Add , , "RootDB", "Europe", 3

rs.MoveFirst

Dim i As Integer
i = 0

Do Until rs.EOF


i = i + 1
countryName = rs.Fields("COUNTRY").Value
NameKey = "N" & Str(i)

TreeView1.Nodes.Add "RootDB", tvwChild, NameKey, countryName, 1



cityName = rs.Fields("CITY").Value
cityKey = "C" & Str(i)

TreeView1.Nodes.Add NameKey, tvwChild, cityKey, cityName , 5


rs.MoveNext

Loop

' --------------------------------------and problem with loop results , what should i change ?
Europe (root)
I
ı_____ Italy
I_____ Rome
ı_____ France
I_____ Paris

Viewing all articles
Browse latest Browse all 15705

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>