The use of anti-SQL injection for C # SQL statement stitching when like case

Source: Internet
Author: User

This afternoon colleagues asked me a more basic question, when splicing SQL statements, if encountered like the situation what to do.

My original writing is a simple concatenation of strings, and later colleagues asked me what to do if I encountered SQL injection. I think about it, it's really a problem.

Just on the Internet to find the relevant instructions, the original is so written.

As such an SQL statement:

  

Select *  from where  like ' % Zhang San% '

In C #, say:

            stringKeywords ="Zhang San"; StringBuilder strSQL=NewStringBuilder (); Strsql.append ("SELECT * from game where gamename like @keywords"); sqlparameter[] Parameters=Newsqlparameter[] {NewSqlParameter ("@keywords","%"+keywords+"%"),             };

Although the use of this is still in% to write, but can effectively filter the SQL injection situation, or is very simple and practical.

is a small knowledge point, I hope you can help! ^_^

The use of anti-SQL injection for C # SQL statement stitching when like case

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.