简体   繁体   中英

how to disable button when its value stored in ms access database vb.net

how button will disable when it's value stored in ms access database vb. net Example button1 value is "101" and when the button1 is clicked the "101" value will display in textbox and when i stored it in the ms access database by using another button, the button1 one will be disabled

If I understand correctly you have two buttons and a textbox. Button1 displays the text displayed on Button1 in the TextBox and then Button2 stores the content of the textbox in the DB (somehow) then disables button1. If so, try this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    TextBox1.Text = Button1.Text
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim DBValue As String = TextBox1.Text
    'Store DBValue in DB
    Button1.Enabled = False
End Sub

If you have multiple buttons and want to find which button was pressed based on the value in textbox1, try this:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    For Each ctrl As Control In Me.Controls
        If (ctrl.GetType() Is GetType(Button)) Then
            Dim btn As Button = ctrl
            If btn.Text = TextBox1.Text Then
                DBValue = TextBox1.Text
                'Store DBValue in DB
                btn.Enabled = False
                Exit For
            End If
        End If
    Next
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM