本文介绍了我有一个代码用于删除VB2012中Access DB中的条目。 MessageBox没有做它应该做的事情。救命。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
        Dim subName As String = txtName.Text
        Dim subadd As String = txtAdd.Text
        Dim subage As String = txtAge.Text
        Dim subsex As String = txtSex.Text
        Dim subOcc As String = txtOcc.Text
        Dim subCS As String = txtCS.Text
        Dim subcn As String = txtCN.Text
        Dim subremarks As String = txtRemarks.Text

        MsgBox("Delete Record?", MsgBoxStyle.YesNo)
        If MsgBoxResult.Yes Then
            provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
            dataFile = "C:\Dr Logger\Dr Logger Files1.accdb"
            connString = provider & dataFile
            myConnection.ConnectionString = connString
            myConnection.Open()
            Dim str As String
            str = "Delete from Logs Where Name = '" & txtName.Text & "'"
            Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
            Try
                cmd.ExecuteNonQuery()
                cmd.Dispose()
                myConnection.Close()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
            ListBox1.Items.Remove(ListBox1.SelectedItem)

            txtName.Text = ""
            txtAdd.Text = ""
            txtAge.Text = ""
            txtSex.Text = "-----"
            txtCN.Text = ""
            txtCS.Text = "-----"
            txtRemarks.Text = ""
            txtOcc.Text = ""
        ElseIf MsgBoxResult.No Then
            txtName.Text = subName
            txtAdd.Text = subadd
            txtAge.Text = subage
            txtSex.Text = subsex
            txtCN.Text = subcn
            txtCS.Text = subCS
            txtRemarks.Text = subremarks
            txtOcc.Text = subOcc
        End If


    End Sub

推荐答案

MsgBox("Delete Record?", MsgBoxStyle.YesNo)
If MsgBoxResult.Yes Then



问题是你没有存储消息框的结果

试试这样的例子


The problem is that you don't store the result of the messagebox
Try for example like this

If MsgBoxResult.Yes = MsgBox("Delete Record?", MsgBoxStyle.YesNo)Then



或者如果你想使用变量那么也许




or if you want to use a variable then perhaps

Dim result
result = MsgBox("Delete Record?", MsgBoxStyle.YesNo)
If MsgBoxResult.Yes Then


Dim result = MsgBox("Delete Record?", MsgBoxStyle.YesNo)
If result = MsgBoxResult.Yes
...


这篇关于我有一个代码用于删除VB2012中Access DB中的条目。 MessageBox没有做它应该做的事情。救命。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 02:35