Reputation: 3
The first part of the program, which reads the database works fine, the problem is with deleting. The database looks like: ID, Username and Text.
The code I'm currently using:
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
Upvotes: 0
Views: 75
Reputation: 424
Are you missing the code that executes the SQL command?
SQLCmd.ExecuteNonQuery()
Upvotes: 1
Reputation: 308763
try this:
strQuery = "Delete FROM otletek WHERE id = " & TextBox2.Text
it's a SQL injection waiting to happen - bad idea.
Upvotes: 0