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 53 54 55 56 57 58 59 60 61 62 63 64
| Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As Any, _
ByVal lpString2 As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, _
Source As Any, ByVal Length As Long)
Public Function loadData(strTab As String)
Dim o_data As clsData
Dim pMyROW As Long
Dim myROW As Long
Dim pLengths As Long
Dim pMyRES As Long
Dim i As Long
Dim j As Long
Dim nbFields As Long
Dim lengths() As Long
Dim texte As String
Dim pMySQL As Long
'initialisation de la connexion
pMySQL = mysql_init(0)
Set o_data = New clsData
'connexion à la base
If mysql_real_connect(pMySQL, "127.0.0.1", "root", "", "BUDGET", 0, "", 0) = 0 Then
MsgBox ("Echec de la connexion à la base")
Else
If (mysql_query(pMySQL, "select ID, MONTANT, LIBELLE, SEMAINE, _DATE from TRANSACT_IN") = 0) Then
pMyRES = mysql_store_result(pMySQL) '<--------------------------pMyRes a pour valeur 0, alors que ma table est remplie
If (pMyRES <> 0) Then
nbFields = mysql_num_fields(pMyRES)
If nbFields > 0 Then
ReDim lengths(0 To nbFields - 1)
For i = 0 To mysql_num_rows(pMyRES) - 1
pMyROW = mysql_fetch_row(pMyRES)
CopyMemory myROW, ByVal pMyROW, 4
pLengths = mysql_fetch_lengths(pMyRES)
CopyMemory lengths(0), ByVal pLengths, 4 * nbFields
For j = 0 To nbFields - 1
texte = Space(lengths(j))
lstrcpy texte, myROW
myROW = myROW + lengths(j) + 1
ListBox1.AddItem texte
Next
Next
End If
End If
mysql_free_result (pMyRES)
End If
End If
'fermeture de la connexion
mysql_close (pMySQL)
End Function |