If you want to prevent XSS vulnerabilities, you need to parse input in a manner that will not allow any browser-side scripting (HTML, JavaScript, or CSS) in your queries. The best thing to do is make a function that will parse queries and escape them properly. You should escape all JavaScript, CSS, and HTML so that no queries can be made with such code in them. This is the simplest and surefire method of dealing with XSS holes on your site. When you are writing with ASP.NET, you usually do not have much to worry about, since it validates requests to prevent malicious scripts before proceeding with the results that come in accordance to the query.