程序的第一部分,读取数据库工作正常,问题是删除。数据库看起来像:ID,用户名和文本。
我目前正在使用的代码:
Public Class Form1
Dim dbCon As MySqlConnection
Dim strQuery As String = ""
Dim SQLCmd As MySqlCommand
Dim dr As MySqlDataReader
Private Sub Delete()
Try
dbCon = New MySqlConnection(Connection string)
strQuery = "Delete * FROM otletek WHERE id = " & TextBox2.Text
SQLCmd = New MySqlCommand(strQuery, dbCon)
dbCon.Open()
MsgBox(strQuery)
dbCon.Close()
Catch ex As Exception
MsgBox("Connection error" & vbCrLf & ex.Message)
End Try
End Sub
答案 0 :(得分:1)
您是否遗漏了执行SQL命令的代码?
SQLCmd.ExecuteNonQuery()
答案 1 :(得分:0)
试试这个:
strQuery = "Delete FROM otletek WHERE id = " & TextBox2.Text
这是一个等待发生的SQL注入 - 糟糕的主意。