喜欢运算符,通配符字符和sqlite中的变量 [英] like operator,wild card charcter and variable in sqlite

查看:87
本文介绍了喜欢运算符,通配符字符和sqlite中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,我正在使用Sqlite.I创建了一个演示应用程序,用户在文本框中传递值,并根据该值程序从数据库中获取数据。目前它正在搜索精确匹配的数据。但是我想要部分匹配意味着如果用户在'seed'处键入'se'而不是显示结果。我尝试了一个解决方案,但它没有获取任何数据。



hello friends, I am working with Sqlite.I created one demo application in which user pass the value in text box and according to that value program fetch the data from data base.currently it is searching data with exact matching.but i want partial matching means if user type 'se' at the place of 'seed' than it shows the result.I tried one solution but it is not fetching any data.

SQLiteCommand sqlite_cmd = new SQLiteCommand("Select *from data where innertext like' %''" + Keyword.Text + "''%'", sqlite_Search);







所以你可以帮忙解决这个问题。




so can you help to solve this issue.

推荐答案

永远不要将值连接到查询中。这使您可以打开Sql注入,数据类型转换问题等。而是使用参数。根据您使用的库,参数类可能会有所不同,但如果您使用的是Devart,那么请查看 http://www.devart.com/dotconnect/sqlite/docs/Devart.Data.SQLite~Devart.Data.SQLite.SQLiteParameter.html [< a href =http://www.devart.com/dotconnect/sqlite/docs/Devart.Data.SQLite~Devart.Data.SQLite.SQLiteParameter.htmltarget =_ blanktitle =New Window> ^ ]。



另请注意,区分大小写可能是没有数据返回的原因。处理此问题的一种方法是在两侧进行小写比较。
Never concatenate values into your query. This leaves you open for Sql injection, data type conversion problems and so on. Instead use parameters. Depending on the library you use the parameter class may differ but if you're using for example Devart then have a look athttp://www.devart.com/dotconnect/sqlite/docs/Devart.Data.SQLite~Devart.Data.SQLite.SQLiteParameter.html[^].

Also note that the case sensitivity may be the reason no data is returned. One way to handle this is to make the comparison in lower case on both sides.


Keyword.Text 之前和之后可能会出现错误撇号或第一个之前的空格。尝试:

May be mistaken apostrophes before and after Keyword.Text or space before the first %. Try:
SQLiteCommand sqlite_cmd = new SQLiteCommand("Select * from data where innertext like '%" + Keyword.Text + "%'", sqlite_Search);


Keyword.Text 的值是多少?可能它包含撇号?我从未使用SQLite,但它应该作为另一个数据库工作
What's the value of Keyword.Text? May be it contains apostrophes? I never used SQLite, but it should work as another databases


这篇关于喜欢运算符,通配符字符和sqlite中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆