asp.net多关键词搜索函数
{
string[] words ={ };
string sql_temp = "", sql = "";
if (keywords != "")
{
words = keywords.Split(' ');
for (int i = 0; i < words.Length; i++)
{
int first = 0;
sql_temp = "( ";
if (first == 0)
{
sql_temp += fileds + " like '%" + words[i] + "%'";
first = 1;
}
else
{
sql_temp += " AND " + fileds + " like '%" + words[i] + "%'"; ;
}
if (sql_temp.Trim() != "(") sql_temp += " ) AND ";
if (i == 0) sql = sql_temp;
else
{
sql += sql_temp;
}
}
sql = sql.Substring(0, sql.LastIndexOf("AND"));
}
return sql;
}