Your site is at serious risk of hacking.
Read on SQL Injection and how to prevent this in .NET.
Your query problem is the least of your problems right now.
But.....
Decision
@Misnomer is close, but not quite there:
Change your request to this:
cmd.CommandText = "SELECT * FROM borrow where (Department LIKE '%@DepartmentText%')"
and add the parameters this way (or how @Misnomer does it):
cmd.Parameters.AddWithValue("@DepartmentText",TextBox2.Text)
The important difference is that you need to change your CommandText.
Abe Miessler Oct 05 2018-10-10 17:55
source share