Jquery+ajax按条件进行模糊查询!? 急急。。。
如题,根据用户输入的内容进行模糊查询,比如说,用户输入了“好”这个字儿进行查询,然后给我找到的是所有包含“好”这个字的数据。以下是我写的代码:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string Cwords = context.Request["Cwords"];
var data = new OnLineDicTableAdapter().GetDataByChWords(Cwords);
if (data.Count == 0)
{
return;
}
List<Words> list = new List<Words>();
foreach (var row in data)
{
list.Add(new Words() {
WID=row.WID,
ChWords=row.ChWords,
UyWords=row.UyWords,
UFrom=row.UFrom,
Usentence=row.USentence,
EWords=row.EWords,
ESentence=row.ESentence,
ChSentence=row.ChSentence
});
}
JavaScriptSerializer jss = new JavaScriptSerializer();
context.Response.Write(jss.Serialize(list));
主要是这个GetDataByChWords(Cwords);方法的sql查询语句怎么写!??
拜托各位大侠了! 先感谢你们!
在线等待答案!
------解决方案--------------------
"select * from tablename where 列名 like '%"+Cwords+"%'";
用参数
"select * from tablename where 列名 like '%'+@Cwords+'%'";