[VB.NET] Variable integer qui reset toujours a 0
Bonjour
Bon voilà, j'utilise une variable int pour n'aviguer dans les rows d'un dataset d'une requête SQL, quand j'appelle ma fonction qui fait i = i + 1, et bien quand la page load mon i redevient 0 à tout les coup, donc quand j'appuie sur le boutton suivant, il va toujours checher la rows(1) de mon dataset. Voici mon code :
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 53 54
| Imports System.Data.SqlClient
Partial Public Class _Default
Inherits System.Web.UI.Page
Private Con As SqlConnection
Private Cmd As SqlCommand
Private Da As SqlDataAdapter
Private Ds As DataSet
Private results As String
Private i As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Con = New SqlConnection("Data Source = CNTNGSOEAMS1\SqlExpress; Initial Catalog = Centraide; Integrated Security = SSPI;")
Cmd = New SqlCommand("Select * from employe where Matricule like '" & TextBox1.Text & "%'", Con)
Da = New SqlDataAdapter(Cmd)
Ds = New DataSet()
Da.Fill(Ds)
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
change_i(0)
Aff_Emp()
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
change_i(1)
Aff_Emp()
End Sub
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click
change_i(-1)
Aff_Emp()
End Sub
Public Sub Aff_Emp()
If Ds.Tables(0).Rows.Count > 0 Then
TextBox2.Text = Ds.Tables(0).Rows(i).Item(0)
TextBox3.Text = Ds.Tables(0).Rows(i).Item(1)
TextBox4.Text = Ds.Tables(0).Rows(i).Item(2)
End If
End Sub
Public Sub change_i(ByVal _i As Integer)
If _i = 0 Then
i = 0
ElseIf _i = 1 Then
i = i + 1
ElseIf _i = -1 Then
If i > 0 Then
i = i - 1
End If
End If
End Sub
End Class |
Merci de m'aider