Converting to C # and ASP. NET about how like in achieves parameterized Query

Source: Internet
Author: User
C #, ASP . Net. For common SQL statements such as select, the normal parameterized statement format is as follows:

Select * From profile where employeeid = @ employeeid

For example:

String loginstring = "select * From profile where employeeid = @ employeeid ";

But please attention to the like SQL sentence:

Select * From profile where employeeid like '%' + @ employeeid + '% ';

The accurate search format is:

Select * From profile where employeeid like + @ employeeid;

So

String = "select * from box where boxid like '%' + @ substring + '% '"

Provides valuable information for this article.ArticleInclude:

C # SQL like Parameter

The significance of parameterization is to provide the corresponding value from the parameter. For the like statement, the value after like includes all the parts in single quotes, including the percent sign (% ), therefore, when parameterizing the like value, you should move the percentage sign to the parameter value, as shown in the following code:

Cmd. Parameters ["@ keyword"]. value = "%" + strkeyword + "% ";

Do not look like this in SQL statements:

Select * from [tablename] Where [column1] Like '% @ keyword %'

No error is reported, but you cannot query the expected results.

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.