发布网友
共4个回答
懂视网
今天终于学会怎么在like中用参数化查询啦。。哈哈。。再也不用担心sql注入了。。。
SQL中的LIKE中用参数化查询
标签:
热心网友
SQL like 需要配合通配符使用。
sql 中的通配符有。
以table_a中的 a 列,来举例
select * from table_a where a like "a%"
--检索a列 以 "a"开头的记录
select * from table_a where a like "%a"
--检索a列 以 "a"结尾的记录
select * from table_a where a like "%a%"
--检索a列 字符中包含“a”的记录
select * from table_a where a like "___"
--检索 a列 只有3个字符的记录
select * from table_a where a like "_a"
--检索a列 只有2个字符,且第二个字符为 “a”的记录
select * from table_a where a like '[abc]%'
--检索a列 以 "a","b","C" 开头的记录
select * from table_a where a like '[!abc]%'
--检索a列 不以 "a","b","C" 开头的记录
热心网友
selcet*
from Directory
Where 书名 like @书名
传递参数的时候,在代码中补充两个百分号。
例如Command.Parameters.AddWithValue(@书名", "%" & book & "%")
说明:&是VB.net的字符串连接符,其他语言请自行修改。
追问你的意思是写成
热心网友
钟内有问