I\'m just wondering if someone could point me in the right direction here, I think i\'ve been looking at it for too long so can\'t see the mistake.
The following code:>
I think you should rather have a look at
SQL Parameters in C#
SqlParameter Class
to try to avoid SQL injection
SQL injection is a code injection technique that exploits a security vulnerability occurring in the database layer of an application. The vulnerability is present when user input is either incorrectly filtered for string literal escape characters embedded in SQL statements or user input is not strongly typed and thereby unexpectedly executed. It is an instance of a more general class of vulnerabilities that can occur whenever one programming or scripting language is embedded inside another. SQL injection attacks are also known as SQL insertion attacks
All in all, you are leaving a massive gap in your application for attacks based on the query string being dynamically created. The quoted error you have will be handled but also avoid any, lets say DROP TABLE USERS