I have this problem by changing the text of added dynamically button.
I want to change the button text from "Select" to "Update".

this is my code.

```
dim oButton as button

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Dim dr As SqlDataReader
    Dim cn As SqlConnection = New SqlConnection("Data Source=server;Initial Catalog=testDB;Integrated Security=True;MultipleActiveResultSets=true;")
    cmd.Connection = cn
    cmd.CommandType = CommandType.StoredProcedure
    cmd.CommandText = "votecand"
    Dim stream As New MemoryStream()
    cn.Open()
    dr = cmd.ExecuteReader
    If dr.HasRows = True Then
       while dr.read
          oButton = New Button
          oButton.Enabled = True
          oButton.Font = New Font("Tahoma", 11, FontStyle.Regular)
          oButton.Location = New Point(ButtonNumber * 30, ButtonNumber * 30)
          oButton.Name = "MyButton" & ButtonNumber.ToString
          oButton.Size = New Size(134, 34)
          oButton.BackColor = Color.MediumSeaGreen
          oButton.FlatStyle = FlatStyle.Flat
          oButton.ForeColor = Color.White
          oButton.Text = "Select"
          oButton.Visible = True
          oButton.Dock = DockStyle.Bottom
          oButton.Tag = ButtonNumber
          AddHandler oButton.Click, AddressOf onButtonClick
          Me.Controls.Add(oButton)
       End while
    End if
End sub

```

this code is MyFunc Function

```
Private Sub MyFunc(ByVal ButtonNumber As Integer)

    Dim cn As SqlConnection = New SqlConnection("Data Source=server;Initial Catalog=testDB;Integrated Security=True;MultipleActiveResultSets=true;")
    Dim command As New SqlCommand

    command = New SqlCommand("select first_name,middle_name,last_name,position,gender,course,year_level,aff,student_id from tbl_cand where id=@id", cn)
    command.Parameters.AddWithValue("@id", SqlDbType.VarChar).Value = ButtonNumber.ToString

    Dim dt As New DataTable()
    Dim adapater As New SqlDataAdapter(command)
    adapater.Fill(dt)

    Dim fname As String = dt.Rows(0).ItemArray(0).ToString
    Dim mname As String = dt.Rows(0).ItemArray(1).ToString
    Dim lname As String = dt.Rows(0).ItemArray(2).ToString
    Dim gender As String = dt.Rows(0).ItemArray(3).ToString
    Dim course As String = dt.Rows(0).ItemArray(4).ToString
    Dim year As String = dt.Rows(0).ItemArray(5).ToString
    Dim aff As String = dt.Rows(0).ItemArray(6).ToString
    Dim studid As String = dt.Rows(0).ItemArray(7).ToString

    lblfname.Text = fname
    lblmname.Text = mname
    lbllname.Text = lname
    lblgender.Text = gender
    lblyear.Text = year
    lblmajor.Text = course
    lblaff.Text = aff

    connect()
    sql = "INSERT INTO tbl_castvote(can_id,fname,img,student_id)"
    sql = sql + "VALUES(@canid,@fname,@pos,@img,@voterid,@stdid)"
    cmd = New SqlCommand(sql, con)
    With cmd
        .Parameters.AddWithValue("canid", studid)
        .Parameters.AddWithValue("fname", fname)

        Dim ms As New MemoryStream()
        pb.Image.Save(ms, pb.Image.RawFormat)
        Dim data As Byte() = ms.GetBuffer()
        Dim p As New SqlParameter("@img", SqlDbType.VarBinary)
        p.Value = data
        .Parameters.Add(p)

        .Parameters.AddWithValue("stdid", studentid.Text)
    End With

    If MsgBox("You have selected" & " '" & fname & " " & mname & " " & lname & "' " & "as" & " '" & pos & "' ", vbOKCancel + vbInformation, "Voting System") = vbOK Then
        cmd.ExecuteNonQuery()
        oButton.Text = "Update" --> this line is my problem. Can't change the oButton.text "Select" to "Update"
    End If

End Sub

```

and this is my button click handler

```
Private Sub onButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Dim ButtonNumber As Integer
    If CType(sender, Button).Tag IsNot Nothing Then
        If Integer.TryParse(CType(sender, Button).Tag.ToString, ButtonNumber) Then
            MyFunc(ButtonNumber)
        End If
    End If
End Sub

```

pls help me. thank you