user3272016
user3272016

Reputation: 3

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

Upvotes: 0

Views: 75

Answers (2)

Jeff Block
Jeff Block

Reputation: 424

Are you missing the code that executes the SQL command?

SQLCmd.ExecuteNonQuery()

Upvotes: 1

duffymo
duffymo

Reputation: 308763

try this:

strQuery = "Delete FROM otletek WHERE id = " & TextBox2.Text

it's a SQL injection waiting to happen - bad idea.

Upvotes: 0

Related Questions