2013-06-12 13 views
0

我正在嘗試排查ASP/C#gridview搜索中一些SQL代碼的故障。我有一個搜索框在特定的字段上搜索,但這裏的扭曲是我只想在某一行之後得到結果。主頁滾動gridview搜索結果中的SQL代碼無法顯示正確的結果

在這個數據庫中,我有一個序列命令,可以在表中爲每個條目自動生成一個名爲'record_number'的列中的數字,並且只需要記錄#500之後的結果。條目通過不同的頁面手動創建。

現在我的搜索代碼如下:

"SelectCommand="SELECT [record_number], [column_a], [column_b], [column_c], [column_d], [column_e], [column_f], [column_g], [column_h], [column_i], [column_j] FROM [schema].[table_name] WHERE record_number >= 500 AND ([column_a] LIKE '%' + @column_a + '%') OR ([column_c] LIKE '%' + @column_c + '%') OR ([column_e] LIKE '%' + @column_e + '%') OR ([column_g] LIKE '%' + @column_g + '%') OR ([column_h] LIKE '%' + @column_h + '%') OR ([column_j] LIKE '%' + @column_j + '%')" 

如果需要的話,我可以張貼我的SelectParameters或其他任何東西。我面臨的挑戰是,當我利用這段代碼搜索字母'c'時,結果發佈的記錄號小於或大於500.此時,我正在旋轉我的輪子,因爲我是沒有看到問題出在哪裏。

如果需要更多信息的羣衆,請讓我知道。

編輯

忘記了這部分 - 我已經試過移動命令周圍,鞏固命令,但沒有去。

回答

0

你試過包裝全部或聲明在(查詢),它幾乎看起來好像它的閱讀它:

(record_number >= 500 AND ([column_a] LIKE '%' + @column_a + '%')) OR ([column_e] LIKE '%' + @column_e + '%') OR ([column_g] LIKE '%' + @column_g + '%') OR ([column_h] LIKE '%' + @column_h + '%') OR ([column_j] LIKE '%' + @column_j + '%') 

而不是:

record_number >= 500 AND (([column_a] LIKE '%' + @column_a + '%') OR ([column_e] LIKE '%' + @column_e + '%') OR ([column_g] LIKE '%' + @column_g + '%') OR ([column_h] LIKE '%' + @column_h + '%') OR ([column_j] LIKE '%' + @column_j + '%')) 

不同之處在於它將> = 500加上column_a的第一個語句作爲一種條件,在這種情況下,其他條件也可以爲true,並且結果爲record_number < 500.

不知道這是你的問題,但我會放棄。

+0

沒有。這沒有用。 –