2014年3月17日 星期一

gridView模糊查詢,該如何處理


http://www.010cnc.net/subject/about/gridView%E6%A8%A1%E7%B3%8A%E6%9F%A5%E8%A9%A2%EF%BC%8C%E8%A9%B2%E5%A6%82%E4%BD%95%E8%99%95%E7%90%86.html

gridView模糊查詢,
搜索條件兩個,一個年份,一個建立者。建立者是模糊查詢。
我想不輸入建立者,只輸入年份,能找到當年所有的記錄。
現在問題是:
必須輸入年份和建立者才能搜索到記錄。

另:
該sql語句在資料庫中執行沒有問題。
select * from pubCostVersion where yearly=2007 and createby like '%%'


 
 
 
 
 
 
 
 
 

 
    SelectCommand="SELECT [Yearly], [Monthly], [isCale], [CreateBy], [CreateTime], [ModifyBy], [ModiFyTime] FROM [pubCostVersion] WHERE (([Yearly] = @Yearly) AND ([CreateBy] LIKE '%' + @CreateBy + '%'))">
 
 
 
 

 




------解決方案--------------------
code=SQL]select * from pubCostVersion where (yearly=null or yearly=2007) and (createby like '%% ' or createby =null)[[/code]

------解決方案--------------------
SQL code
   select * from pubCostVersion where (yearly=null or yearly=2007) and  (createby like   '%%  ' or createby =null)  
------解決方案--------------------
不用那麼麻煩.你用like就行了:
SelectCommand="SELECT [Yearly], [Monthly], [isCale], [CreateBy], [CreateTime], [ModifyBy], [ModiFyTime] FROM [pubCostVersion] WHERE (([Yearly] like '%"+@Yearly+"%') AND (([CreateBy] LIKE  '% " + @CreateBy +  "% ')))"  
------解決方案--------------------
SelectCommand="SELECT [Yearly], [Monthly], [isCale], [CreateBy], [CreateTime], [ModifyBy], [ModiFyTime] FROM [pubCostVersion] WHERE (([Yearly] = @Yearly) AND ((@CreateBy = '') or ([CreateBy] LIKE  '% ' + @CreateBy +  '% ')))" >            
Bookmark the permalink ,來源:互聯網

沒有留言: