my son is enrolled in your school. His name is:
Robert'); DROP TABLE STUDENT; --
We call him little Bobby Tables.
Okay, I have been told that this was going to be deleted as not an answer and that I needed to fall on the sword or clean up my own mess. Although I'll keep
my rep if it gets deleted I think it is important to point out the vulnerability in the OP's code (may his account rest in peace). So lemme elaborate...
Let's actually fix the above name from the XKCD comic to something that would actually work against the concatenated query (assuming OP's boolean issue has been fixed):
123; DROP TABLE STUDENT; --
If we add this in the sidnolabel
text box (or whatever it is; if it is in the viewstate you could change it with a simple tool), the resulting concatenated query is
update Student
set send_mail = 1
where student_id = 123; DROP TABLE STUDENT; --'
which will run a bogus query then drop the Student table.
This is the definition of "not good."
What OP should be doing is using a parameterized query. This prevents injection attacks like this. Updating OP's code...
Try
conSQL.Open()
Dim cmd As New SqlCommand(
"update Student " + _
"set send_mail = @sendMail " + _
"where student_id = @studentId", conSQL)
cmd.Parameters.Add( _
"@sendMail", SqlDbType.Bit).Value = _
sendemailCheckBox.Checked
cmd.Parameters.Add( _
"@studentId", SqlDbType.NChar, 25).Value = _
sidnolabel.Text ' better to keep track of this in the Session!
cmd.ExecuteNonQuery()
Finally
conSQL.Close()
End Try
Which should fix OP's issue and prevent sql injection attacks. Ain't that something?
*Please note, I don't VB, and this is not tested. Any VB.NET devs who want to edit and fix errors I'll be happy to accept your help.