简体   繁体   中英

how to match any part of string?

I have an column something like:

name         value 
John kennedy 1999
Bill gates   8388383
Obama        11110

I need an query that match 1999 if I try get john or kennedy

I tried it:

  cmd.CommandText = "select value from contacts where name like @name";
  cmd.Parameters.AddWithValue("@name", "%" + name);

if @name is john this returns 0 colums if '@name' is kennedy this returns 1999

在名称的两边都加上%

cmd.Parameters.AddWithValue("@name", "%" + name + "%");

您可以尝试:

cmd.Parameters.AddWithValue("@name", "%" + name + "%");

您需要在值的两端使用通配符:

cmd.Parameters.AddWithValue("@name", "%" + name + "%");

似乎与参数值的大小写有关,请尝试将列值和参数值设置为大写或小写以及在您的SQL中,看看是否有帮助

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM