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

Recommended Answers

All 5 Replies

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.

For some reason, the program is now deleting. :) Thank You.

What is the data type of a check box and radio button in MS SQL?

Be a part of the DaniWeb community

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