Search code examples
mysqldatabasevb.netsql-delete

I would like to delete a row from a MySQL Database


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

Solution

  • Are you missing the code that executes the SQL command?

    SQLCmd.ExecuteNonQuery()