-2

This is a tennis tournament simulation program I'm Trying to make a tree. Everything its working perfectly but I have a big problem. I can't progress to the next stage with the winners of the firts games. Because I can't change the "target" label where I want to write the winners name. Here's a print:enter image description here

This is how I Generate the winners who is going to the next stage and it actually works.~

Public Sub Gerar_Vencedor(Atleta1, Atleta2)
    Using con As New OleDb.OleDbConnection
        con.ConnectionString = "Provider = Microsoft.ACE.OLEDB.12.0;" &
                               "Data Source = E:\dev\Ganso\BaseDados_ClubeTenis.accdb"
        con.Close()
        con.Open()
        Dim busca = "Select Vencedor From Jogo Where idAtleta1 = '" & Atleta1 & "' and idAtleta2 = '" & Atleta2 & "'"
        Dim cmd As OleDbCommand = New OleDbCommand(busca, con)
        Dim dr As OleDbDataReader = cmd.ExecuteReader()
        ' A variável sql vai receber a string para fazer o select a base de dados
        'Try
        ' é aberta ligação a Bdados
        ' declaração de um comando que vai executar a instrução sql na base de dados
        ' variável que vai receber os registos resultantes da instrução sql
        ' ciclo que vai percorrer todos os registos do comando anterior
        While dr.Read()
            Label9.Text = dr("Vencedor")
        End While
        con.Close()
    End Using
End Sub

My problem is that Label9.Text = dr("Vencedor") because everytime I get a winner it goes to label9. My final question is: Is there anyway to dynamically change the label without repeating this function over and over.

Thanks.

João Figueiredo
  • 107
  • 1
  • 1
  • 12
  • You could pass in a label or make the method smarter to get multiple items and populate them from the results. Do Not concat strings to make SQL;also you are leaking resources – Ňɏssa Pøngjǣrdenlarp Jun 29 '17 at 00:12

1 Answers1

1

Can You Try

Dim i As Integer = 9
While dr.Read()

If i < 15

DirectCast(Me.Controls("Label" & i), Label).Text = dr("Vencedor")

Else

End If

i = i + 1

End While