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()

Recommended Answers

All 3 Replies

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.

you asked this question already here: http://www.daniweb.com/forums/thread241370.html

I agree. If you see double threads in the future, you can click the 'flag bad post' link so that a moderator can come along and merge or close the threads.

Closed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.