ListViewCtrl : lire données
Bonjour,
J'uilise une ListViewCtrl pour aller lire une basse acces.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| Sub OnClick(Byval Item)
'-------- Déclaration des variables
Dim objConnection, objCommand, objRecordset, strConnectionString
Dim strSQL, lngCount , lngValue
'----------------------------------------
'----- Atention la base doi avoir plus d'un ligne
'-------------------------------------
strConnectionString = "Provider=MSDASQL;DSN=SampleDSN;UID=;PWD=;"
strSQL = "SELECT * FROM WINCC_COURBES;"
Set objConnection = CreateObject("ADODB.Connection")
objConnection.ConnectionString = strConnectionString
objConnection.Open
Set objRecordset = CreateObject("ADODB.Recordset")
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = strSQL
Set objRecordset = objCommand.Execute
lngCount = objRecordset.Fields.Count
'MISE AJOUR DE LA VARIABLE
If (lngCount>0) Then
objRecordset.movefirst
Dim oList,oItem
Set oList = HMIRuntime.ActiveScreen.ScreenItems("ListTable")
oList.ListItems.Clear
Do While Not objRecordset.EOF
Set oItem = oList.ListItems.Add()
oItem.Text = objRecordset.Fields(0).Value
oItem.SubItems(1) = objRecordset.Fields(1).Value
oItem.SubItems(2) = objRecordset.Fields(2).Value
oItem.SubItems(3) = objRecordset.Fields(3).Value
oItem.SubItems(4) = objRecordset.Fields(4).Value
objRecordset.MoveNext
Loop
End If
End Sub |
Je sélectionné une ligne.
Comment faire pour récupèree les valeurs de chaque colonnes ?