查詢的問題,請各位老師幫我吧^^ |
答題得分者是:tech_state
|
life124
一般會員 發表:21 回覆:11 積分:6 註冊:2003-05-07 發送簡訊給我 |
各位老師,我這位笨蛋新手又來了,謝謝各位老師的教導。
以下是我打的查詢方法,
String s;
s="select * from Tabel1" ;
s=s " Where id='" Edit1->Text "'" ;
if(Edit2->Text !="")
s=s "or fatid" Edit2->Text ;
if (Edit3->Text !="")
s=s "or monid" Edit3->Text ;
if (Edit4->Text !="")
s=s "or red" Edit4->Text ;
if(Edit5->Text !="")
s=s "or addess" Edit5->Text;
Query1->Close () ;
Query1->SQL->Clear () ;
Query1->SQL->Add (s);
Query1->Open() ; 問題出現了,就是當我執行ok,把所要查詢的東西打下去後,有些沒打,會出現
以下錯,
project project1.exe raised exception class EDBEengine error with
message 'General SQL error.
[Miriosort][ODBC Miriosort Access Driver]參數太少,預期個1。
'Process Stopped. Use Step or run continue. 還有一種是把要查詢的東西打滿了,會出現以下錯,
project project1.exe raised exception class EDBEengine error with
message 'General SQL error.
[Miriosort][ODBC Miriosort Access Driver]'id=31'or fatid=456 or monid=756 or coclr=red or adderr=gogo ' 中的語法錯,(少了運算元)
'Process Stopped. Use Step or run continue. 請問各位老師這是錯什麼,可不可以幫我改一下啊,我的想法是
例:把妳所知的打下去,不知的可以空白的查詢
請各位老師幫我解解吧。謝謝
|
chih
版主 發表:48 回覆:1186 積分:639 註冊:2002-04-02 發送簡訊給我 |
你的or 應該要改成 AND,還有Edit1.Text應該也要判斷是不是空白吧??
String s;
s="select * from Tabel1" ;
s=s " Where 1=1' ;
if(Edit1->Text !="")
s=s " AND id='" Edit1->Text "'" ;
if(Edit2->Text !="")
s=s " AND fatid" Edit2->Text ;
if (Edit3->Text !="")
s=s " AND monid" Edit3->Text ;
if (Edit4->Text !="")
s=s " AND red" Edit4->Text ;
if(Edit5->Text !="")
s=s " AND addess" Edit5->Text;
Query1->Close () ;
Query1->SQL->Clear () ;
Query1->SQL->Add (s);
Query1->Open() ;
TRY TRY SEE
|
tech_state
版主 發表:44 回覆:638 積分:641 註冊:2003-02-10 發送簡訊給我 |
引言: 各位老師,我這位笨蛋新手又來了,謝謝各位老師的教導。 以下是我打的查詢方法, String s; s="select * from Tabel1" ; s=s " Where id='" Edit1->Text "'" ; if(Edit2->Text !="") s=s "or fatid" Edit2->Text ; if (Edit3->Text !="") s=s "or monid" Edit3->Text ; if (Edit4->Text !="") s=s "or red" Edit4->Text ; if(Edit5->Text !="") s=s "or addess" Edit5->Text; Query1->Close () ; Query1->SQL->Clear () ; Query1->SQL->Add (s); Query1->Open() ; 問題出現了,就是當我執行ok,把所要查詢的東西打下去後,有些沒打,會出現 以下錯, project project1.exe raised exception class EDBEengine error with message 'General SQL error. [Miriosort][ODBC Miriosort Access Driver]參數太少,預期個1。 'Process Stopped. Use Step or run continue. 還有一種是把要查詢的東西打滿了,會出現以下錯, project project1.exe raised exception class EDBEengine error with message 'General SQL error. [Miriosort][ODBC Miriosort Access Driver]'id=31'or fatid=456 or monid=756 or coclr=red or adderr=gogo ' 中的語法錯,(少了運算元) 'Process Stopped. Use Step or run continue. 請問各位老師這是錯什麼,可不可以幫我改一下啊,我的想法是 例:把妳所知的打下去,不知的可以空白的查詢 請各位老師幫我解解吧。謝謝life124, 您好 s="select * from Tabel1 where 1=1 " ; if(Edit1->Text != "") s=s " or id='" Edit1->Text "'" ; if(Edit2->Text !="") s=s "or fatid = '" Edit2->Text "'" ; if (Edit3->Text !="") s=s "or monid = '" Edit3->Text "'" ; if (Edit4->Text !="") s=s "or red = '" Edit4->Text "'" ; if(Edit5->Text !="") s=s "or addess = '" Edit5->Text "'";試試看,也請注意紅色字部分。 至於是用or 還是用and 就要看您的需求了。 ======================= 是非終日有,不聽自然無 天下本無事,庸人自擾之 發表人 - tech_state 於 2003/05/08 10:03:11 |
life124
一般會員 發表:21 回覆:11 積分:6 註冊:2003-05-07 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |