Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

strsql = "delete from student_info where Student_No = " & ctrl & ""

Dim sqlcmd As New SqlClient.SqlCommand
sqlcmd.CommandText = strsql
sqlcmd.Connection = sqlconn

MsgBox("Student Deleted")

When I try to delete a student in the list view the error points to Sqlcmd.ExecuteNonQuery() and it says Incorrect syntax near '='.

I don't know what's wrong I tried

strsql = "delete from student_info where Student_No = '" & ctrl & "'"

then there's no error and when I try to delete it, it says Student Deleted but after I clicked on OK the student is not deleted.

Help me please. Thank you :D

6 Years
Discussion Span
Last Post by aishapot

For troubleshooting purposes add debug.print strsql before or after sqlcmd.ExecuteNonQuery() .
This will return (in the output window while debugging) the exact statement you are passing to SQL server, with values and everything. If it looks correct, copy/paste it on your SQL and verify that you get the intended result.


No, it's still not working. :(
It says student deleted but it still didn't remove the student i want to delete.


It wasn't supposed to fix anything. It will only show you the exact SQL statement that your program tries to execute (including values for parameters).
Debug your program and when you click button1 you will see in VS in the output window your SQL statement. copy and paste it into your SQL server.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.