“WHERE [title] LIKE @title”
@title=%标题%
我刚做了一个多重搜索,你参考一下(使用了一个小技巧,1=1)。
(除了下面的方法,使用sqldatasource的过滤功能也挺不错,在你的MSDN中输入:
ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.chs/dv_vwdcon/html/aff9e910-8460-4c12-a2e0-529dce65ec52.htm)
protected string GetSelectCommand()
{
//SetSearchParams();
StringBuilder sb = new StringBuilder();
if(this.count!=null)
sb.Append("SELECT TOP (@Count) FileID,Title,UploadUser,UploadTime,ModifyTime,CatalogID,KeyWords,UploadIP,FilePath,DisplayOrder,Size,FileType,Status FROM [FileInfo]");
else
sb.Append("SELECT FileID,Title,UploadUser,UploadTime,ModifyTime,CatalogID,KeyWords,UploadIP,FilePath,DisplayOrder,Size,FileType,Status FROM [FileInfo]");
sb.Append(" WHERE (1=1)");
//}
if (!string.IsNullOrEmpty(keyWord))
{
if (this.isFullTextSearch)
{ sb.Append(" AND (Title LIKE @KeyWord OR KeyWords LIKE @KeyWord OR Description LIKE @Keyword)"); }
else
{
sb.Append(" AND (Title LIKE @KeyWord OR KeyWords LIKE @KeyWord)");
}
}
if (cataID != 0)
{
sb.Append(" AND (CatalogID=@CatalogID)");
}
if (!String.IsNullOrEmpty(fileType))
{
sb.Append(" AND (FileType=@FileType)");
}
if (upperFileSize != null)
{
sb.Append(" AND (Size<@UpperFileSize)");
}
if (lowerFileSize != null)
{
sb.Append(" AND (Size>@LowerFileSize)");
}
if (upperUploadTime != null)
{
sb.Append(" AND (UploadTime<@UpperUploadTime)");
}
if (lowerUploadTime != null)
{
sb.Append(" AND (UploadTime>@lowerUploadTime)");
}
if (!String.IsNullOrEmpty(userName))
{
sb.Append(" AND (UploadUser LIKE @UploadUser)");
}
sb.Append(" ORDER BY UploadTime");
sb.Append(" DESC");
return sb.ToString();
}