[英]how to change to query in delphi
procedure TGateScanForm.ebContainerKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
Found: Boolean;
begin
if Key = VK_RETURN then
begin
ebContainer.ValidateEdit(True);
if not BookingContainer.Active then BookingContainer.Open;
Found:= BookingContainer.Locate('no_container', ebContainer.Text, []);
if Found then
begin
no_booking:= BookingContainer.FieldByName('no_booking').Value;
no_bc11:= BookingContainer.FieldByName('no_bc11').Value;
no_container:= BookingContainer.FieldByName('no_container').Value;
statCont:= BookingContainer.FieldByName('status_container').Value;
statBooking:= BookingContainerstatus.Value;
bProses.Enabled:= True;
Key := VK_TAB;
end
else
begin
bProses.Enabled:= False;
BookingContainer.Close;
ShowMessage('Nomor Container tidak ditemukan');
end;
end;
end;
The qusetion is how i can convert the below line to query. qusetion是我如何将以下行转换为查询。
Found:= BookingContainer.Locate('no_container', ebContainer.Text, []); 找到:= BookingContainer.Locate('no_container',ebContainer.Text,[]);
If I have understood correctly, you may use : 如果我理解正确,则可以使用:
function Found(S : string) : boolean;
begin
try
**Unsafe code:**
MyQuery.SQL := Format('SELECT NO_CONTAINER FROM TABLE_BookingContainer
WHERE NO_CONTAINER = ''%s''',[S]);
**Safe code:**
MyQuery.SQL := 'SELECT NO_CONTAINER FROM TABLE_BookingContainer
WHERE NO_CONTAINER = :p);
MyQuery.Params.ParamByName('p').AsString = s;
MyQuery.Open;
result := MyQuery.FieldByName('NO_CONTAINER').Value <> null;
finnaly
MyQuery.Close;
end;
end;
to execute function may use : 执行功能可以使用:
....
if Found(ebContainer.Text) then
.......
I don't know what for Dataset you use but something like this can search on the database. 我不知道您使用什么数据集,但是可以在数据库中搜索类似的内容。
BookingContainer.Close;
BookingContainer.SQL.Text := 'SELECT * FROM Table WHERE no_container= :no_container';
BookingContainer.Parameters.ParamByName('no_container').Value := ebContainer.Text;
BookingContainer.Open;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.