query 콤포넌트를 사용해서 update 를 하려 합니다..
이렇게 말로 하는 것보단 코딩을 보느게 낫겠죠??
procedure TMainScrn.btnInsertStockClick(Sender: TObject);
var
OldNo: String;
OldNoI, NewNoI, TotalNoI: Integer;
begin
qryStockB.Close;
qryStockB.SQL.Clear;
qryStockB.SQL.Add('Select count(*) from StockB');
qryStockB.SQL.Add('where ItemID=:f1');
qryStockB.Params.ParamByName('f1').AsString:= edtStockItemID.Text;
qryStockB.Open;
if qryStockB.Fields[0].AsInteger > 1 then
begin
ShowMessage('Hyung, Big Mistake!!!');
qryStockB.Close;
halt(1);
end;
if qryStockB.Fields[0].AsInteger = 0 then
begin
qryPart.close;
qryPart.sql.clear;
qryPart.Sql.add('insert into Part');
qryPart.sql.add('values ( :f1,:f2,:f3,:f4,:f5)');
qryPart.params.ParamByName('f2').asstring:= edtStockItemName.text;
qryPart.params.ParamByName('f3').asstring:= edtStockNo.Text;
qryPart.params.ParamByName('f4').asstring:= edtStockSupplierID.text;
qryPart.params.ParamByName('f5').asstring:= edtStockDate.text;
qryPart.ExecSQL;
qryPart.close;
qryStockP.Close;
qryStockP.sql.clear;
qryStockP.Sql.add('insert into StockP');
qryStockP.sql.add('values ( :f1,:f2,:f3)');
qryStockP.params.ParamByName('f1').asstring:= edtStockItemID.text;
qryStockP.params.ParamByName('f2').asstring:= edtStockItemName.text;
qryStockP.params.ParamByName('f3').asstring:= edtStockAmount.Text;
qryStockP.ExecSQL;
qryStockP.close;
qryStockB.Close;
qryStockB.sql.clear;
qryStockB.Sql.add('insert into StockB');
qryStockB.sql.add('values ( :f1,:f2,:f3)');
qryStockB.params.ParamByName('f1').asstring:= edtStockItemID.text;
qryStockB.params.ParamByName('f2').asstring:= edtStockItemName.text;
qryStockB.params.ParamByName('f3').asstring:= edtStockNO.Text;
qryStockB.ExecSQL;
qryStockB.close;
ShowMessage('Record Inserted');
end
else if (qryStockB.Fields[0].AsInteger = 1) then
begin
qryPart.close;
qryPart.sql.clear;
qryPart.Sql.add('insert into Part');
qryPart.sql.add('values ( :f1,:f2,:f3,:f4,:f5)');
qryPart.params.ParamByName('f1').asstring:= edtStockItemID.text;
qryPart.params.ParamByName('f2').asstring:= edtStockItemName.text;
qryPart.params.ParamByName('f3').asstring:= edtStockNo.Text;
qryPart.params.ParamByName('f4').asstring:= edtStockSupplierID.text;
qryPart.params.ParamByName('f5').asstring:= edtStockDate.text;
qryPart.ExecSQL;
qryPart.close;
qryStockP.Close;
qryStockP.sql.clear;
qryStockP.Sql.add('update StockP');
qryStockP.sql.add('set Amount=:f3');
qryStockP.SQL.add('where ItemID=:f1');
qryStockP.params.ParamByName('f1').asstring:= edtStockItemID.text;
qryStockP.params.ParamByName('f3').asstring:= edtStockAmount.Text;
qryStockB.Close;
qryStockB.SQL.Clear;
qryStockB.SQL.Add('Select * from StockB');
qryStockB.SQL.Add('where ItemID =:f1');
qryStockB.Params.ParamByName('f1').AsString:= edtStockItemID.text;
qryStockB.Open;
OldNo:= qryStockB.Fields[2].AsString;
OldNoI:= StrToInt(OldNo);
NewNoI:= StrToInt(edtStockNo.Text);
TotalNoI:= OldNoI + NewNoI;
qryStockB.Close;
qryStockB.SQL.Clear;
qryStockB.Sql.add('update StockB');
qryStockB.sql.add('set No=:f3 ');
qryStockB.SQL.add('where ItemID=:f1');
qryStockB.params.ParamByName('f1').asstring:= edtStockItemID.text;
qryStockB.params.ParamByName('f3').asstring:= IntToStr(TotalNoI);
try
qryStockB.ExecSQL;
qryStockP.ExecSQL;
except
showmessage('Could not update table --> Record Locked by another user');
end;
qryStockB.close;
qryStockP.close;
ShowMessage('Record Updated');
end;
edtStockItemID.Clear;
edtStockItemName.Clear;
edtStockAmount.Clear;
edtStockNo.Clear;
edtStockSupplierID.Clear;
edtStockDate.Clear;
end;
이부분입니다..
일단 StockB 라는 table 이 있고, 이 table은 ItemID 와 ItemName 과 No 라는 필드를 가지고 있습니다.. 이 procedure는 insert부분과 update 부분으로 이루어져 있고, 제가 질문을 드리고 싶은 부분은 update 부분으로, 이미 들어가있는 No 필드의 값을 ItemID 넘버에 따라 새로들어오는값에 더해서 그 No 필드의 값을 그 더한 값으로 update 해주는 것입니다..
그런데, 아무래도 제생각에는,
qryStockB.params.ParamByName('f3').asstring:= IntToStr(TotalNoI);
이 라인이 안도는것 같습니다..
에러 메시지가
Project simplewareproject.exe raised exception class EDBEngingError with message 'Invalid use of Keyword. Token: No=? Line Number:2.' Process stopped. Use step or Run to continue.
입니다..
관심있으신 고수님들 답변 주시면 호주가이드는 제가 책임지고(성은에 보답하고자 물론 무료) 하겠습니다..
> query 콤포넌트를 사용해서 update 를 하려 합니다..
> 이렇게 말로 하는 것보단 코딩을 보느게 낫겠죠??
>
> procedure TMainScrn.btnInsertStockClick(Sender: TObject);
> var
> OldNo: String;
> OldNoI, NewNoI, TotalNoI: Integer;
> begin
> qryStockB.Close;
> qryStockB.SQL.Clear;
> qryStockB.SQL.Add('Select count(*) from StockB');
> qryStockB.SQL.Add('where ItemID=:f1');
> qryStockB.Params.ParamByName('f1').AsString:= edtStockItemID.Text;
> qryStockB.Open;
>
> if qryStockB.Fields[0].AsInteger > 1 then
> begin
> ShowMessage('Hyung, Big Mistake!!!');
> qryStockB.Close;
> halt(1);
> end;
>
> if qryStockB.Fields[0].AsInteger = 0 then
> begin
> qryPart.close;
> qryPart.sql.clear;
> qryPart.Sql.add('insert into Part');
> qryPart.sql.add('values ( :f1,:f2,:f3,:f4,:f5)');
> qryPart.params.ParamByName('f2').asstring:= edtStockItemName.text;
> qryPart.params.ParamByName('f3').asstring:= edtStockNo.Text;
> qryPart.params.ParamByName('f4').asstring:= edtStockSupplierID.text;
> qryPart.params.ParamByName('f5').asstring:= edtStockDate.text;
> qryPart.ExecSQL;
> qryPart.close;
>
>
>
> qryStockP.Close;
> qryStockP.sql.clear;
> qryStockP.Sql.add('insert into StockP');
> qryStockP.sql.add('values ( :f1,:f2,:f3)');
> qryStockP.params.ParamByName('f1').asstring:= edtStockItemID.text;
> qryStockP.params.ParamByName('f2').asstring:= edtStockItemName.text;
> qryStockP.params.ParamByName('f3').asstring:= edtStockAmount.Text;
> qryStockP.ExecSQL;
> qryStockP.close;
>
>
>
>
> qryStockB.Close;
> qryStockB.sql.clear;
> qryStockB.Sql.add('insert into StockB');
> qryStockB.sql.add('values ( :f1,:f2,:f3)');
> qryStockB.params.ParamByName('f1').asstring:= edtStockItemID.text;
> qryStockB.params.ParamByName('f2').asstring:= edtStockItemName.text;
> qryStockB.params.ParamByName('f3').asstring:= edtStockNO.Text;
> qryStockB.ExecSQL;
> qryStockB.close;
> ShowMessage('Record Inserted');
> end
> else if (qryStockB.Fields[0].AsInteger = 1) then
> begin
> qryPart.close;
> qryPart.sql.clear;
> qryPart.Sql.add('insert into Part');
> qryPart.sql.add('values ( :f1,:f2,:f3,:f4,:f5)');
> qryPart.params.ParamByName('f1').asstring:= edtStockItemID.text;
> qryPart.params.ParamByName('f2').asstring:= edtStockItemName.text;
> qryPart.params.ParamByName('f3').asstring:= edtStockNo.Text;
> qryPart.params.ParamByName('f4').asstring:= edtStockSupplierID.text;
> qryPart.params.ParamByName('f5').asstring:= edtStockDate.text;
> qryPart.ExecSQL;
> qryPart.close;
>
>
>
>
> qryStockP.Close;
> qryStockP.sql.clear;
> qryStockP.Sql.add('update StockP');
> qryStockP.sql.add('set Amount=:f3');
> qryStockP.SQL.add('where ItemID=:f1');
> qryStockP.params.ParamByName('f1').asstring:= edtStockItemID.text;
> qryStockP.params.ParamByName('f3').asstring:= edtStockAmount.Text;
>
>
>
>
> qryStockB.Close;
> qryStockB.SQL.Clear;
> qryStockB.SQL.Add('Select * from StockB');
> qryStockB.SQL.Add('where ItemID =:f1');
> qryStockB.Params.ParamByName('f1').AsString:= edtStockItemID.text;
> qryStockB.Open;
> OldNo:= qryStockB.Fields[2].AsString;
>
>
> OldNoI:= StrToInt(OldNo);
> NewNoI:= StrToInt(edtStockNo.Text);
> TotalNoI:= OldNoI + NewNoI;
>
> qryStockB.Close;
> qryStockB.SQL.Clear;
> qryStockB.Sql.add('update StockB');
> qryStockB.sql.add('set No=:f3 ');
> qryStockB.SQL.add('where ItemID=:f1');
> qryStockB.params.ParamByName('f1').asstring:= edtStockItemID.text;
> qryStockB.params.ParamByName('f3').asstring:= IntToStr(TotalNoI);
>
> try
> qryStockB.ExecSQL;
> qryStockP.ExecSQL;
> except
> showmessage('Could not update table --> Record Locked by another user');
> end;
> qryStockB.close;
> qryStockP.close;
> ShowMessage('Record Updated');
> end;
>
>
>
> edtStockItemID.Clear;
> edtStockItemName.Clear;
> edtStockAmount.Clear;
> edtStockNo.Clear;
> edtStockSupplierID.Clear;
> edtStockDate.Clear;
>
> end;
>
>
> 이부분입니다..
>
> 에러 메시지가
> Project simplewareproject.exe raised exception class EDBEngingError with message 'Invalid use of Keyword. Token: No=? Line Number:2.' Process stopped. Use step or Run to continue.
> 입니다..
>
에러 메시지가 있으므로 에러메시지를 충분히 확인하는 것이 필요하겠죠??
키워드를 썼다고 나오네요. 'No'라는 update문장 2번째줄에..
아마도 'No'라는 단어가 'Not~' 'NOWAIT~'등등이 있으므로 오라클 예약어로 분류되어
있지 않을까 싶네요. 만약 오라클예약어로 되어있다면 필드이름을 수정해야겠죠?!