插入的时候,某一字段的值是从另外的一个表中读取的! 比如下面代码段中的depid字段,是从dept表中读取的!!
SQLstmt:='insert into "stainfo"'+
'(stano,sname,sex,depid)VALUES (:InpStano,:InpSname,:InpSex,:depid)
这里的depid该如何替换掉~~
注意:在access数据库中~~
SQLstmt:='insert into "stainfo"'+
'(stano,sname,sex,depid)VALUES (:InpStano,:InpSname,:InpSex,:depid)
这里的depid该如何替换掉~~
注意:在access数据库中~~
用query2控件來取得depid字段。
query1.close;
query1.sql.clear;
query1.sql.text:=sqlstmt;
query1.parambyname('depid').value:=query2.fieldbyname('depid').asstring;
query1.open;注意轉換時的數據類型。還有query2要有數據。
begin
with adoquery2 do
begin
//这里用adoquery2查询数据库,从dept表中读取depid字段,并定位到相应记录
end;
with ADOQuery1 do
begin
Close;
sql.Clear;
sql.Add('insert into stainfo(stano,sname,sex,depid) values(:InpStano,:InpSname,:InpSex,:depid)') ;
Parameters.ParamByName('InpStano').Value :=1 ;
Parameters.ParamByName('InpSname').Value :='wudi' ;
Parameters.ParamByName('InpSex').Value :=1 ;
Parameters.ParamByName('depid').Value :=adoquery2.fieldbyname('depid').value;
ExecSQL
end;
end;
只在SQL语句中,如何实现???
各位老大,帮帮忙阿~~ 谢谢哈
'(stano,sname,sex,depid)VALUES (:InpStano,:InpSname,:InpSex,:depid)
你没有给条件,所以没法定义到具体的记录,给你,你自己加条件吧SQLstmt:='insert into "stainfo"'+
'(stano,sname,sex,depid)VALUES (:InpStano,:InpSname,:InpSex,(select depid from dept where 条件))
你的方法中where条件能不能使用变量?? 比如 select id form dept where dep="&InpDep&"
InpDep 是变量!!
select id form dept where dep=:InpDep
在ADOQuery1里调参数