查詢問題 |
|
monkeyhung
一般會員 發表:51 回覆:55 積分:21 註冊:2006-12-16 發送簡訊給我 |
各位大大為什麼我用二個欄位下去RUN時是可以的
Query2.Close; Query2.SQL.Clear; Query2.SQL.Add('Select * from prod'); Query2.SQL.Add('where 1 = 1 '); if trim(Edit1.Text) <> '' then Query2.SQL.Add(' and prodno = ''' trim(Edit1.Text) ''' '); if trim(Edit18.Text) <> '' then Query2.SQL.Add(' and packno = ''' trim(Edit18.Text) ''' '); Query2.Open; 但若用很多欄位下去查詢時卻找不出任何資料耶,RUN時也沒有出錯呀 Query2.Close; Query2.SQL.Clear; Query2.SQL.Add('Select * from prod'); Query2.SQL.Add('where 1 = 1 '); if trim(Edit1.Text) <> '' then Query2.SQL.Add(' and prodno = ''' trim(Edit1.Text) ''' '); if trim(Edit18.Text) <> '' then Query2.SQL.Add(' and packno = ''' trim(Edit18.Text) ''' '); if trim(edit19.Text) <> '' then query2.SQL.Add(' and sw = "' trim(edit19.text) '"'); if trim(edit20.Text) <> '' then query2.SQL.Add(' and id = "' trim(edit20.text) '"'); if trim(edit21.Text) <> '' then query2.SQL.Add(' and od = "' trim(edit21.text) '"'); if trim(edit22.Text) <> '' then query2.SQL.Add(' and ar = "' trim(edit22.text) '"'); if trim(edit23.Text) <> '' then query2.SQL.Add(' and pr = "' trim(edit23.text) '"'); if combobox5.text <> '' then query2.SQL.Add(' and br = "' (combobox5.text) '"'); if trim(edit27.Text) <> '' then query2.SQL.Add(' and pa = "' trim(edit27.text) '"'); if trim(edit26.Text) <> '' then query2.SQL.Add(' and sr = "' trim(edit26.text) '"'); if trim(edit25.Text) <> '' then query2.SQL.Add(' and va = "' trim(edit25.text) '"'); if trim(edit24.Text) <> '' then query2.SQL.Add(' and brand = "' trim(edit24.text) '"'); if trim(edit28.Text) <> '' then query2.SQL.Add(' and pword = "' trim(edit28.text) '"'); if combobox6.text <> '' then query2.SQL.Add(' and ptype = "' (combobox6.text) '"'); if combobox7.text <> '' then query2.SQL.Add(' and stype = "' (combobox7.text) '"'); if combobox8.text <> '' then query2.SQL.Add(' and flag = "' (combobox8.text) '"'); query2.open |
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
|
chuang7287
初階會員 發表:1 回覆:20 積分:29 註冊:2002-10-22 發送簡訊給我 |
我純粹用猜的(因為看不到你的資料)
你應該檢查Combobox6.text , Combobox7.text , Combobox8.text 的值, 通常ComboBox的內容會是"代號" "名稱",而資料庫儲存資料只會填寫"代號" 此時當你去Select 資料時,永遠也找不到資料. if combobox6.text <> '' then query2.SQL.Add(' and ptype = "' (combobox6.text) '"'); if combobox7.text <> '' then query2.SQL.Add(' and stype = "' (combobox7.text) '"'); if combobox8.text <> '' then query2.SQL.Add(' and flag = "' (combobox8.text) '"'); 若要判斷你的SQL與法是否有問題,你也可以在Query2.Open之前 showmessage(Query2.SQL.Text) 查看你的SQL語法及傳入的資料是否正確
------
結案=動力 高手等等我 .... 追隨高手永不懈怠!! |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |