有關比對資料庫有無相同資料問題 |
答題得分者是:pedro
|
Fen
一般會員 發表:18 回覆:17 積分:7 註冊:2003-10-20 發送簡訊給我 |
各位大大:
我現在要做一個功能,是讓使用者修改DBGrid中的資料,當使用者按下存檔後,先去比對資料庫中有無相同的資料,但是因為DBGrid一變更,游標一移動,就會自動存回資料庫,所以不管怎麼比對都有資料;若將Locktype改成ltBatchOptimistic,則在第一筆修改後按存檔,他會跑去比對第二筆,下面附上我程式,請各位大大幫忙一下,看我哪裡有錯。
tableDetail2D.First;
while not tableDetail2D.Eof do
begin
if QueryCheck.Active then
QueryCheck.Active := False;
QueryCheck.SQL.Clear;
begin
QueryCheck.SQL.Add('SELECT A.* , B.* FROM MoldIssueNotice
A,MoldIssueNoticePartsDetail B');
QueryCheck.SQL.Add('WHERE A.IssueNotice=B.IssueNotice AND
DevCode = :PARA1 AND Gender = :PARA2 AND Size = :PARA3 ');
QueryCheck.SQL.Add('AND MoldPurpose = :Para4 AND MoldCycle
= :Para5 ');
end; QueryCheck.Parameters.ParamByName('PARA1').Value := txtDevCode.Text;
QueryCheck.Parameters.ParamByName('PARA2').Value := txtGender.Text;
QueryCheck.Parameters.ParamByName('PARA3').Value := txtSize.Text;
QueryCheck.Parameters.ParamByName('PARA4').Value :=
DBGridDetail2D.Fields[5].AsInteger;
QueryCheck.Parameters.ParamByName('PARA5').Value :=
DBGridDetail2D.Fields[6].AsString;
QueryCheck.Active := True; if not QueryCheck.Eof then
begin
MessageDlg('部位編號: ' IntToStr(tableDetail2D.FieldValues
['PrtId']) ',開模目的:' tableDetail2D.FieldValues
['MoldPurpose'] ',模具輪次:' tableDetail2D.FieldValues
['MoldCycle'] ',於系統中存在相同記錄!! (開模通知單編號: '
IntToStr(QueryCheck.FieldValues['IssueNotice']) ' )',
mtInformation, [mbOK], 0);
exit;
end
else
begin
tableDetail2D.Next;
end;
end; 我是用D5 SQLServer!!
|
pedro
尊榮會員 發表:152 回覆:1187 積分:892 註冊:2002-06-12 發送簡訊給我 |
Fen您好, 您這段程式碼是不是放在要檢查的table之OnBeforePost事件之中?
還有遇到資料庫有相同資料時, 是否用abort使程式不去post相同資料
到table裡?
tableDetail2D.First; while not tableDetail2D.Eof do begin if QueryCheck.Active then QueryCheck.Active := False; QueryCheck.SQL.Clear; begin QueryCheck.SQL.Add('SELECT A.* , B.* FROM MoldIssueNotice A,MoldIssueNoticePartsDetail B'); QueryCheck.SQL.Add('WHERE A.IssueNotice=B.IssueNotice AND DevCode = :PARA1 AND Gender = :PARA2 AND Size = :PARA3 '); QueryCheck.SQL.Add('AND MoldPurpose = :Para4 AND MoldCycle = :Para5 '); end; QueryCheck.Parameters.ParamByName('PARA1').Value := txtDevCode.Text; QueryCheck.Parameters.ParamByName('PARA2').Value := txtGender.Text; QueryCheck.Parameters.ParamByName('PARA3').Value := txtSize.Text; QueryCheck.Parameters.ParamByName('PARA4').Value := DBGridDetail2D.Fields[5].AsInteger; QueryCheck.Parameters.ParamByName('PARA5').Value := DBGridDetail2D.Fields[6].AsString; QueryCheck.Active := True; if not QueryCheck.Eof then begin MessageDlg('部位編號: ' IntToStr(tableDetail2D.FieldValues ['PrtId']) ',開模目的:' tableDetail2D.FieldValues ['MoldPurpose'] ',模具輪次:' tableDetail2D.FieldValues ['MoldCycle'] ',於系統中存在相同記錄!! (開模通知單編號: ' IntToStr(QueryCheck.FieldValues['IssueNotice']) ' )', mtInformation, [mbOK], 0); exit; end else begin tableDetail2D.Next; end; end; |
chun0che
一般會員 發表:0 回覆:2 積分:0 註冊:2003-05-16 發送簡訊給我 |
|
Fen
一般會員 發表:18 回覆:17 積分:7 註冊:2003-10-20 發送簡訊給我 |
|
ying0515
中階會員 發表:90 回覆:168 積分:81 註冊:2003-01-04 發送簡訊給我 |
|
Fen
一般會員 發表:18 回覆:17 積分:7 註冊:2003-10-20 發送簡訊給我 |
|
pedro
尊榮會員 發表:152 回覆:1187 積分:892 註冊:2002-06-12 發送簡訊給我 |
|
chun0che
一般會員 發表:0 回覆:2 積分:0 註冊:2003-05-16 發送簡訊給我 |
|
ying0515
中階會員 發表:90 回覆:168 積分:81 註冊:2003-01-04 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |