I'm using a combobox connected to my account numbers in mysql..I want to take the selecteditem and put it in the delete row string for mysql using vb.net....her is what I have so far and it wont delete the seleted..any help will do....

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        'delete selected row from database

        Dim Ans As MsgBoxResult
        ' Set icon to exclamation mark
        ' Set buttons to OK and Cancel
        ' Show Message Box
        Ans = MsgBox("Are you sure you want to Delete Selected Account?", vbYesNo + vbExclamation, "Yes or No")
        ' If the user clicked no exit sub
        If Ans = vbNo Then
            Exit Sub
        End If
        'if the user clicked yes then delete selected row from database
        If Ans = vbYes Then
            Dim account_number As String
            account_number = CBAccountNumber.SelectedItem(1)

            Dim mysql As String

            mysql = "SELECT * DELETE FROM customer WHERE account_number="""
            ' selects dependent record from Contacts, deletes then refreshes

        End If

        Me.Close()

Edited 7 Years Ago by __avd: Added [code] tags. Encase your code in: [code] and [/code] tags.

I'm using a combobox connected to my account numbers in mysql..I want to take the selecteditem and put it in the delete row string for mysql using vb.net....her is what I have so far and it wont delete the seleted..any help will do....

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
'delete selected row from database

Dim Ans As MsgBoxResult
' Set icon to exclamation mark
' Set buttons to OK and Cancel
' Show Message Box
Ans = MsgBox("Are you sure you want to Delete Selected Account?", vbYesNo + vbExclamation, "Yes or No")
' If the user clicked no exit sub
If Ans = vbNo Then
Exit Sub
End If
'if the user clicked yes then delete selected row from database
If Ans = vbYes Then
Dim account_number As String
account_number = CBAccountNumber.SelectedItem(1)

Dim mysql As String

mysql = "SELECT * DELETE FROM customer WHERE account_number="""
' selects dependent record from Contacts, deletes then refreshes

End If

Me.Close()

Just out of curiosity, i see a couple of things not right. you have

mysql = "SELECT * DELETE FROM customer WHERE account_number ="""

I would think you would want that line to look like

mysql = "DELETE FROM customer WHERE account_number = '" & account_number & "'"

This sql statement is saying "DELETE FROM <table_name> WHERE <field_name> = <criteria>"

Hope this helps, this is just the obvious thing that i can see with your code without running it on my end to test and alas, i am not running mysql in my windows environment.

This article has been dead for over six months. Start a new discussion instead.