搜索功能 where部分

搜索功能where部分
publicstring keywords(string SearchField, string keyWord)
{
if (keyWord !=null& keyWord !="")
{
string strKeyword = keyWord.Replace("'", "''");
string strTemp ="";
string strSubQuery =" and";
string[] KeywordArray;
KeywordArray
= strKeyword.Split(null);

if (KeywordArray.Length <2)
{
strSubQuery
=""+ SearchField +" like '%"+ strKeyword +"%'";
}
elseif (KeywordArray.Length ==2|| KeywordArray.Length ==3)
{
strTemp
="";
for (int i =0; i < KeywordArray.Length; i++)
{
strTemp
+=""+ SearchField +" like '%"+ KeywordArray[i] +"%' and";
}
strTemp
= strTemp.TrimEnd(newchar[] { 'a', 'n', 'd' });
strSubQuery
= strTemp;
}
elseif (KeywordArray.Length >3)
{
strSubQuery
=""+ SearchField +"=''";
}
return strSubQuery;
}
returnnull;
}
 
 本文是抄袭别人代码 非本人原创
ps:徐兄,抱歉了啦,你的代码被我分享哦,只因写的太好太有实用价值,不能独留 ^.^
     (谁让你写代码不加注释。。看苦我了。。。) 
 
原文地址:https://www.cnblogs.com/itstone/p/2046219.html