線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:976
推到 Plurk!
推到 Facebook!

sql 問題

答題得分者是:ha0009
chrislao
初階會員


發表:86
回覆:69
積分:36
註冊:2002-12-28

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-09-03 21:11:56 IP:202.175.xxx.xxx 未訂閱
在sqlquerry 的sql屬性內輸入下列的一句sql select * from employee where username = :susername and passwd = :spassword procedure TLoginForm.bbtnOKClick(Sender: TObject); begin sqlqLogin.Params.ParamByName('susername').Value:=edtUsername.Text; sqlqLogin.Params.ParamByName('spassword').Value:=edtPassword.Text; sqlqLogin.ExecSQL(true); if sqlqLogin.RecordCount<>0 then showmessage('Login OK!') else showmessage('Login Fail!'); end; 為甚麼會出錯?
cashxin2002
版主


發表:231
回覆:2555
積分:1937
註冊:2003-03-28

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-09-03 21:31:07 IP:63.84.xxx.xxx 未訂閱
您好!    Select語法查詢請使用Open , 不要使用ExecSQL. 另外, 請將下兩句: sqlqLogin.Params.ParamByName('susername').Value:=edtUsername.Text; sqlqLogin.Params.ParamByName('spassword').Value:=edtPassword.Text; 改為: sqlqLogin.Params.ParamByName('susername').AsString:=edtUsername.Text; sqlqLogin.Params.ParamByName('spassword').AsString:=edtPassword.Text; 因為使用Value, 當edtUsername和edtPassword為null時是會出錯的. Value無法判斷空字串, 使用AsString會將Null自動傳為'' 參考看看! ===================== 努力,相信會獲得美麗! 忻晟 發表人 - cashxin2002 於 2003/09/03 21:35:00
------
忻晟
chrislao
初階會員


發表:86
回覆:69
積分:36
註冊:2002-12-28

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-09-03 21:55:36 IP:202.175.xxx.xxx 未訂閱
仍會出現 dbexpress error:operation not supported
terrychen
尊榮會員


發表:90
回覆:794
積分:501
註冊:2003-05-01

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-09-03 23:42:21 IP:211.76.xxx.xxx 未訂閱
chrislao 兄 誠如cashxin2002兄所言 Select語法查詢請使用Open , 不要使用ExecSQL 因為ExecSQL不會有傳回值 看起來您是用DBexpress 用ADO聯結試試看 我試過可以阿
chih
版主


發表:48
回覆:1186
積分:639
註冊:2002-04-02

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-09-03 23:46:13 IP:218.165.xxx.xxx 未訂閱
procedure TLoginForm.bbtnOKClick(Sender: TObject); begin sqlqLogin.Close; sqlqLogin.SQL.Clear; sqlqLogin.SQL.ADD('select * from employee where username = :susername and passwd = :spassword '); sqlqLogin.Params.ParamByName('susername').Value:=edtUsername.Text; sqlqLogin.Params.ParamByName('spassword').Value:=edtPassword.Text; sqlqLogin.Open; if sqlqLogin.RecordCount<>0 then showmessage('Login OK!') else showmessage('Login Fail!'); end; TRY TRY SEE
chrislao
初階會員


發表:86
回覆:69
積分:36
註冊:2002-12-28

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-09-04 01:00:55 IP:202.175.xxx.xxx 未訂閱
chih版主,我已經按照你的方法做,但當我一輸入username和password就會在 if sqlqLogin.RecordCount<>0 then 這句出錯, dbexpress error:operation not supported 請問是甚麼原因?
ha0009
版主


發表:16
回覆:507
積分:639
註冊:2002-03-16

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-09-04 01:35:41 IP:61.56.xxx.xxx 未訂閱
你好: 這可能是你所連結的資料庫不支援 RecordCount 的原因吧。 如果是這樣的話你可以使用下列方式取代。原理是當資料表一開啟時除非是空表 否則 Bof 與 Eof 絕對不可能一樣。
sqlqLogin.open;
if (sqlqLogin.Bof = sqlqLogin.Eof) then
   showmessage('Login OK!')
else
   showmessage('Login Fail!');
摘錄 RecordCount文件說明 Use the RecordCount property to find out how many records are in a Recordset object. The property returns -1 when ADO cannot determine the number of records or if the provider or cursor type does not support RecordCount. Reading the RecordCount property on a closed Recordset causes an error.
cashxin2002
版主


發表:231
回覆:2555
積分:1937
註冊:2003-03-28

發送簡訊給我
#8 引用回覆 回覆 發表時間:2003-09-04 01:43:03 IP:63.84.xxx.xxx 未訂閱
您好!    出錯信息是運算子無支援, 所以試試: if sqlqLogin.RecordCount > 0 then ===================== 努力,相信會獲得美麗! 忻晟
------
忻晟
cashxin2002
版主


發表:231
回覆:2555
積分:1937
註冊:2003-03-28

發送簡訊給我
#9 引用回覆 回覆 發表時間:2003-09-04 01:53:47 IP:63.84.xxx.xxx 未訂閱
引言: 你好: 這可能是你所連結的資料庫不支援 RecordCount 的原因吧。 如果是這樣的話你可以使用下列方式取代。原理是當資料表一開啟時除非是空表 否則 Bof 與 Eof 絕對不可能一樣。
sqlqLogin.open;
if (sqlqLogin.Bof = sqlqLogin.Eof) then
   showmessage('Login OK!')
else
   showmessage('Login Fail!');
摘錄 RecordCount文件說明 Use the RecordCount property to find out how many records are in a Recordset object. The property returns -1 when ADO cannot determine the number of records or if the provider or cursor type does not support RecordCount. Reading the RecordCount property on a closed Recordset causes an error.
至ha0009版主 還記得小弟吧< >, 借此篇問題之寶地, 感謝您的多次幫助, 不過近來都很少見到您< >, 蠻想念的啦! 看您答題快破百了, 先恭喜在前, 這應該是earliest屬性的恭喜元件吧 您以上的><>===================== 努力,相信會獲得美麗! 忻晟 發表人 -
------
忻晟
chrislao
初階會員


發表:86
回覆:69
積分:36
註冊:2002-12-28

發送簡訊給我
#10 引用回覆 回覆 發表時間:2003-09-04 10:28:55 IP:202.175.xxx.xxx 未訂閱
ha0009你好: 多謝你的指教,問題已解決,完來是mysql不支援recordcount
系統時間:2024-07-01 20:05:30
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!