我用的是Access数据库,Delphi6,
有两个表A,B
A表字段:
ID 自动编号
Name char
sex boolean
B表字段:
ID int
Name char
Sex boolean
Adr char(not null)
Tel int (not null)
通过选定的ID号将A表记录插入到B表中,我用的是
'insert into tab2 select * from tab1 where id='+''+inttostr(strtoint(ID))+'',
以上语句在B表中最后两个字段可为空时还能运行正常,可当最后两个字段不可为空时就出错了,不知如何在交换记录时同时为最后两个字段插入一个默认值呢?某不才,还请各位老大赐教一二!!
有两个表A,B
A表字段:
ID 自动编号
Name char
sex boolean
B表字段:
ID int
Name char
Sex boolean
Adr char(not null)
Tel int (not null)
通过选定的ID号将A表记录插入到B表中,我用的是
'insert into tab2 select * from tab1 where id='+''+inttostr(strtoint(ID))+'',
以上语句在B表中最后两个字段可为空时还能运行正常,可当最后两个字段不可为空时就出错了,不知如何在交换记录时同时为最后两个字段插入一个默认值呢?某不才,还请各位老大赐教一二!!
应该是:
insert into tab2 where 字段X=(select 字段X from tab1 where id='+''+inttostr(strtoint(ID))+''
name:=dbgrid1.Fields[1].Value;
sex:=dbgrid1.Fields[2].Value;
with adoquery2 do
begin
Close;
Sql.Clear;
Sql.Add('insert into B values(:id1,:name1,:sex1,:temp1,:temp2)');
Parameters.ParamByName('id1').Value:=i;
parameters.ParamByName('name1').Value:=name;
parameters.ParamByName('sex1').Value:=sex;
parameters.ParamByName('temp1').Value:='defaut';
parameters.ParamByName('temp2').Value:='defaut';
Prepared;
ExecSQL;
end;delphi7+sql 2000通过;