請問這段新增與刪除的程式碼程序解說

如何使用文字敘訴這段程序

新增↓ Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

Me.Visible = False

f2 = New InsertForm()

f2.Show()

End Sub

刪除↓

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click

If MsgBox("確定刪除記錄:" & currentpid, MsgBoxStyle.YesNo) _

= MsgBoxResult.Yes Then

cnn.Open()

cmd.CommandText = "delete from AddressBook where pid = " & currentpid

MessageBox.Show(cmd.CommandText)

cmd.Connection = cnn

cmd.CommandType = CommandType.Text

cmd.ExecuteNonQuery()

cmd.Dispose()

cnn.Close()

resetForm()

End If

End Sub

End Class

1 個解答

評分
  • 1 0 年前
    最佳解答

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

    '隱藏目前的Form

    Me.Visible = False

    'Show出新增資料的Form

    f2 = New InsertForm()

    f2.Show()

    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click

    '彈出確認對話框,如果選擇Yes,則執資料刪除的程式

    If MsgBox("確定刪除記錄:" & currentpid, MsgBoxStyle.YesNo) _

    = MsgBoxResult.Yes Then

    '開始連線

    cnn.Open()

    '刪除資料的 sql script

    cmd.CommandText = "delete from AddressBook where pid = " & currentpid

    'debug用

    'MessageBox.Show(cmd.CommandText)

    '設定command 物件的連線資訊

    cmd.Connection = cnn

    '設定command 物件的 sql script 命令

    cmd.CommandType = CommandType.Text

    '連線資料庫,執行命令

    cmd.ExecuteNonQuery()

    'command 物件Dispose

    cmd.Dispose()

    '結束連線

    cnn.Close()

    '這看你問的上一篇吧

    resetForm()

    End If

    End Sub

    End Class

還有問題?馬上發問,尋求解答。