目前我正在尝试使用我的解决方案从ms访问中删除数据,但它目前无法正常工作。我在按钮删除时列出了消息框,但它没有显示,并且在我启动它时没有显示任何错误。这是代码:
MessageBox.Show("Are You Sure You Want To Delete?", "Deletion",_
MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If DialogResult.Yes Then
Function1()
UserHomepage.Show()
Me.Hide()
ElseIf DialogResult.No Then
Me.Show()
UserHomepage.Hide()
lblname.Hide()
txtsid.ResetText()
End If
cmdDelete.CommandText = "Delete from student where student_id = " + txtsid.Text + ";"
cmdDelete.CommandType = CommandType.Text
cmdDelete.Connection = cnnOLEDB
cmdDelete.ExecuteNonQuery()
这是针对功能1 ^
答案 0 :(得分:0)
`
Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
Dim dr As DialogResult = MessageBox.Show("Are You Sure You Want To Delete?", "Deletion",
MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If dr = DialogResult.Yes Then
Using cnnOLEDB As New OleDb.OleDbConnection("Your connection string")
Using cmdDelete As New OleDbCommand("Delete from student where student_id = @ID;", cnnOLEDB)
cmdDelete.CommandType = CommandType.Text
cmdDelete.Parameters.Add("@ID", OleDbType.Integer).Value = txtsid.Text
cnnOLEDB.Open()
cmdDelete.ExecuteNonQuery()
cnnOLEDB.Close()
End Using
End Using
UserHomepage.Show()
Me.Hide()
Else
Me.Show()
UserHomepage.Hide()
lblname.Hide()
txtsid.ResetText()
End If
End Sub`