zoukankan      html  css  js  c++  java
  • asp.net中like 使用参数化(转)

     

    asp.net中like 使用参数化(2009-12-01 15:34:30)

    标签:

    杂谈

    分类: 遇到并解决之SQL

    对于 普通的 selectsql语句, 正常的参数化 语句 格式:

              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 the

            String   = "SELECT   * from   Box   WHERE   BoxID   like   '%'   +   @subString   +   '%'"

    对本文提供了有价值的文章有:

    c# sql like 参数

    2008-08-08 10:09

    参数化的意义在于把对应的值从参数中提供,对于like语句,like后面的值则包括了单引号中的所有部分,包括百分号(%),因此在参数化like对应的值时,应该把百分号移到参数值中提供,像这样:

    Cmd.Parameters["@KeyWord"].Value = "%" + StrKeyWord + "%";

    可别奢想在sql语句中像这样的样子:

    Select * From [TableName] Where [Column1] like '%@KeyWord%'

    不会报错,不过你不可能查询到想要的结果

  • 相关阅读:
    Repeater控件用法
    python的文件锁使用
    python的文件锁使用
    python的文件锁使用
    linux下文件描述符的介绍
    linux下文件描述符的介绍
    linux下文件描述符的介绍
    Linux 2.6 中的文件锁
    Linux 2.6 中的文件锁
    Linux 2.6 中的文件锁
  • 原文地址:https://www.cnblogs.com/liubo68/p/2736619.html
Copyright © 2011-2022 走看看