0

I am working vb.net in visual stdio 2005.
I want to delete a row from my table the tables's name is displayed in listbox, when I press delete button in my app nothing happen's.

 Private Sub cmdDELETE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDELETE.Click
        Me.SqlConnection1.Open()
        Dim mycom As SqlCommand
        Dim ra As Integer
        mycom = New SqlCommand("DELETE @PICTUREDATA From pic WHERE 
        (NAME = '+ ListBox1.SelectedItem + ')", Me.SqlConnection1)
        ra = mycom.ExecuteNonQuery()
        MessageBox.Show("ROWS AFFECTED " & ra)
        Me.SqlConnection1.Close()
    End Sub

any help plzz

1
  • Can you try executing the query DELETE @PICTUREDATA From pic WHERE (NAME = '+ ListBox1.SelectedItem + ') " - with the Selected item value as passed to the code - directly in the DB and check if that achieves the desired result? The code SEEMS pretty OK..u will need to debug it to really pinpoint where the problem lies.. Commented Aug 29, 2010 at 4:45

1 Answer 1

2

If you have copy-pasted the code, there is at least one error with quoting. It should be like this:

mycom = New SqlCommand("DELETE @PICTUREDATA From pic WHERE 
(NAME = '" + ListBox1.SelectedItem + "')", Me.SqlConnection1

But you should really consider using the SqlCommand.Parameters collection to add your input data. Your code is open to SQL injection attacks.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.