如果单击,如何更改命令按钮的名称?

时间:2017-03-01 14:10:50

标签: database vb.net

我想更改"编辑"的名称按钮到"更新"按钮并切换编辑按钮的功能以更新按钮...有人请帮助... 这是我的代码:

If EDIT.Text = "Edit" Then
        TextBox8.Text = DataGridView1.SelectedCells(1).Value()
        TextBox1.Text = DataGridView1.SelectedCells(2).Value()
        TextBox2.Text = DataGridView1.SelectedCells(3).Value()
        TextBox3.Text = DataGridView1.SelectedCells(4).Value()
        TextBox4.Text = DataGridView1.SelectedCells(5).Value()
        TextBox5.Text = DataGridView1.SelectedCells(6).Value()
        TextBox6.Text = DataGridView1.SelectedCells(7).Value()
        ComboBox1.Text = DataGridView1.SelectedCells(8).Value()
        TextBox9.Text = DataGridView1.SelectedCells(9).Value()
        DataGridView1.Enabled = False
        EDIT.Text = "Update"
    ElseIf EDIT.Text = "Update" Then
        Dim cmd As New MySqlCommand
        connect.Open()
        cmd.Connection = connect
        da = New MySqlDataAdapter("Select * from tbl_book_info", connect)
        cmd.CommandText = "update tbl_book_info set (Title = '" & TextBox1.Text & "', Author = '" & TextBox2.Text & "',Copyright = '" & TextBox3.Text & "',Publisher = '" & TextBox4.Text & "',Place = '" & TextBox5.Text & "',Copies = '" & TextBox6.Text & "',Subject = '" & ComboBox1.Text & "',ClassNo = '" & TextBox8.Text & "',Registered = '" & TextBox9.Text & "',Time = '" & TextBox10.Text & "',Date = '" & TextBox11.Text & "')"
        cmd.ExecuteNonQuery()
        MsgBox("Done!")

        data = New DataTable()
        DataGridView1.DataSource = data

        da = New MySqlDataAdapter("Select * from tbl_book_info", connect)
        da.Fill(data)

        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
        TextBox5.Text = ""
        TextBox6.Text = ""
        ComboBox1.Text = ""
        TextBox8.Text = ""
        TextBox9.Text = ""

        connect.Close()
    End If

0 个答案:

没有答案