SQL in and like parameterization

Source: Internet
Author: User

The SQL statement is in the like parameter and is not implemented in the normal way
Our general thinking is:

Like parameter:
String strSQL = "SELECT * from person.address where city like '% @add% '";
Sqlparameter[] Parameters=new sqlparameter[1];
Parameters[0] = new SqlParameter ("@add", "Bre");

In Parameter
String strSQL = "SELECT * from Person.Address where Addressid in (@add)";
sqlparameter[] Parameters = new Sqlparameter[1];
Parameters[0] = new SqlParameter ("@add", "343,372,11481,11533,11535,11755,11884,12092,12093,12143");

But this is put in the program can not be executed, even if not error, but also the search results,
Go online Search also did not have a clear answer, after repeated experiments, finally solve the problem
The correct solution is as follows:

Like parameter
String strSQL = "SELECT * from person.address where city like '% ' + @add + '% '";
Sqlparameter[] Parameters=new sqlparameter[1];
Parameters[0] = new SqlParameter ("@add", "Bre");

In Parameter
String strSQL = "EXEC (' select * from Person.Address where addressid in (' [email protected]+ ') ')";
sqlparameter[] Parameters = new Sqlparameter[1];
Parameters[0] = new SqlParameter ("@add", "343,372,11481,11533,11535,11755,11884,12092,12093,12143");

SQL in and like parameterization

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.