全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:983
推到 Plurk!
推到 Facebook!

用TSQLQuery刪除資料如何得知共有幾筆被刪除?

尚未結案
apl
一般會員


發表:5
回覆:4
積分:1
註冊:2003-04-08

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-01-05 22:37:06 IP:218.168.xxx.xxx 未訂閱
如題,若是update的話,可由RowsAffected得知,那delete呢?
 
with dbxq do // dbxq: TSQLQuery
begin
  Close;
  SQL.Text:='delete from TBL_TEST where ID>100';
  ExecSQL(True);  
end;//with
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-01-06 07:36:26 IP:202.39.xxx.xxx 未訂閱
看 Help 的說明, 應該也是從 RowsAffected 屬性中得知: When the SQL dataset represents a query that does not return a result set, you cant use the RecordCount property to ascertain the number of records affected by the query. In such cases, read RowsAffected to determine how many rows were updated or deleted by the query when it executed. If no rows were updated or deleted, RowsAffected is zero. RowsAffected is ? if the SQL statement could not be executed due to an error condition. (This latter situation typically follows the throwing of an exception.)    --- Everything I say is a lie. --<-<-<@
apl
一般會員


發表:5
回覆:4
積分:1
註冊:2003-04-08

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-01-06 09:17:13 IP:211.22.xxx.xxx 未訂閱
我用RowsAffected結果都是0,但資料的確有刪除成功。 另外,上述刪除動作是在交易內進行,呼叫RowsAffected是在交易Commit之前,這有關係嗎?
//aTD: TTransactionDesc
//dbxConn: TSQLConnection
dbxConn.StartTransaction(aTD);
try
 with dbxq do // dbxq: TSQLQuery
 begin
  Close;
  SQL.Text:='delete from TBL_TEST where ID>100';
  ExecSQL(True);
  ShowMessage('刪除筆數='   IntToStr(RowsAffected));  
 end;//with
 dbxConn.Commit(aTD);
except
 dbxConn.Rollback(aTD);
end;
ps. 文章預視時,加號(' ')好像都顯示不出來,是不是有問題? 發表人 - apl 於 2004/01/06 09:22:22
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-01-06 09:43:30 IP:202.39.xxx.xxx 未訂閱
dbexpress 的 Bug, 參考: http://groups.google.com.tw/groups?hl=zh-TW&lr=&ie=UTF-8&inlang=zh-TW&th=7a52521f0ea6c7b0&rnum=1 http://groups.google.com.tw/groups?hl=zh-TW&lr=&ie=UTF-8&inlang=zh-TW&th=6f2f271edefc2745&rnum=2    --- Everything I say is a lie. --<-<-<@
apl
一般會員


發表:5
回覆:4
積分:1
註冊:2003-04-08

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-01-06 10:26:36 IP:211.22.xxx.xxx 未訂閱
了解,謝謝!
系統時間:2024-09-10 6:16:31
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!