请问如何将查询到的结果插入到表中 (20分)

  • 主题发起人 主题发起人 board
  • 开始时间 开始时间
B

board

Unregistered / Unconfirmed
GUEST, unregistred user!
一个表单中有一个dbgrid1
formshow里面写select语句,并将查询的结果显示到dbgrid1中,这个时候dbgrid1中的cj字段为空
procedure Tcj_tj.FormShow(Sender: TObject);
begin
try
adoquery1.Close;
adoquery1.sql.Clear;
adoquery1.SQL.Add('select a.kkjs as 任课教师,a.kcmc as 课程名称,b.xh as 学号 ,c.xm as 姓名,case c.xb when ''0'' then ''女'' else ''男'' end as 性别 ,c.xz as 学制,a.jxbh as 教学班号,d.bjjc1 as 班级, e.cj as 成绩');
adoquery1.SQL.Add('from kb a,xkmd b,xjjbxx c,dm_bj d,xqxscj e ' );
adoquery1.SQL.Add('where a.tnumber='''+number+''' and (a.kcdm=b.kcdm and a.jxbh=b.jxbh) and b.xh= c.xh and c.bjdm=d.bjdm and (e.kcdm=b.kcdm and b.jxbh=e.jxbh and e.xh=b.xh)');
adoquery1.SQL.Add('order by a.jxbh ,e.xh');
AdoQuery1.Open;
colum;//procedure Tcj_tj.colum;
begin
DBGrid1.Columns[0].Width:=60;
DBGrid1.Columns[1].Width:=60;
DBGrid1.Columns[2].Width:=60;
DBGrid1.Columns[3].Width:=60;
DBGrid1.Columns[4].Width:=30;
DBGrid1.Columns[5].Width:=30;
DBGrid1.Columns[6].Width:=50;
DBGrid1.Columns[7].Width:=40;
DBGrid1.Columns[8].Width:=30;
end;
spskinstdlabel1.Caption:='教师编号为'+number+'的老师,您所教的学生成绩如下:';
except
on Exception do raise exception.Create('服务器登陆失败')
end;
end;


当我点击修改按钮时,dbgrid1中的cj字段可写,用户往里面输入数据,然后再点击保存,将用户刚才输入的数据保存到表xqxscj中
procedure Tcj_tj.spSkinButton1Click(Sender: TObject);
begin
with adoquery1 do
adoquery1.close;
adoquery1.sql.clear;
adoquery1.sql.add('insert into xqxscj(xh) values('''+dbgrid1.Columns[2].Field.asstring+''')');
adoquery1.ExecSQL;

end;
上面是我写的代码,但是出错了
请问代码如何实现?
 
SELECT 字段 INTO 表 FROM
 
试一下insert into xqxscj(xh) values("'+dbgrid1.Columns[2].Field.asstring+'")
 
to wjhx
看我的代码先
 
procedure Tcj_tj.spSkinButton1Click(Sender: TObject);
begin
with adoquery1 do
adoquery1.close;
adoquery1.sql.clear;
adoquery1.sql.add(format('insert into xqxscj(xh) values(''%s'')', [dbgrid1.Columns[2].Field]));
adoquery1.ExecSQL;

end;

 
后退
顶部