问题描述
- 利用delphi录入数据时代码错误问题
-
procedure TFrm_stu_ins.Button1Click(Sender: TObject);begin
//写入数据
if (Trim(edt_name.Text)<>'') and (Trim(edt_numb.Text)<>'' ) and (Trim(edt_id.Text)<>'') then
begin
dm.q_stu_ins_ins.close;
dm.q_stu_ins_ins.SQL.Clear;
dm.q_stu_ins_ins.SQL.Add('insert into tbl_base(clm_cls_numb,clm_name,clm_sex,clm_numb,clm_id,clm_add,clm_QQ,clm_mob,clm_mail) valueS(:t1,:t2,:t3,:t4,:t5,:t6,:t7,:t8,:t9)');
// trim
dm.q_stu_ins_ins.Parameters.ParamByName('t1).Value:=Trim(edt_cls_numb.Text);
dm.q_stu_ins_ins.Parameters.ParamByName('t2').Value:=Trim(edt_name.Text);
dm.q_stu_ins_ins.Parameters.ParamByName('t3').Value:=Trim(edt_sex.Text);
dm.q_stu_ins_ins.Parameters.ParamByName('t4').Value:=Trim(edt_numb.Text);
dm.q_stu_ins_ins.Parameters.ParamByName('t5').Value:=Trim(edt_id.Text);
dm.q_stu_ins_ins.Parameters.ParamByName('t6').Value:=Trim(edt_add.Text);
dm.q_stu_ins_ins.Parameters.ParamByName('t7').Value:=Trim(edt_qq.Text);
dm.q_stu_ins_ins.Parameters.ParamByName('t8').Value:=Trim(edt_mob.Text);
dm.q_stu_ins_ins.Parameters.ParamByName('t9').Value:=Trim(edt_mail.Text);
dm.q_stu_ins_ins.ExecSQL;// 重新列出表中数据
DBGrid1.DataSource:=dm.ds_stu_ins_grid;
dm.ds_stu_ins_grid.DataSet:=dm.q_stu_ins_grid;
dm.q_stu_ins_grid.Active:=false;
dm.q_stu_ins_grid.Connection:=dm.conn;
dm.q_stu_ins_grid.SQL.clear;
dm.q_stu_ins_grid.SQL.Add('select * from tbl_base order by clm_r_id desc');
dm.q_stu_ins_grid.Active:=true;
end
else
Begin
ShowMessage('姓名、学号、身份证号不能为空');end;
end;
end.运行代码是出现问题‘project stu.exe raised exception class EDatabaseError with message 'q_stu_ins_ins:parameter 't1' not found'.process stopped. use step or run to continue.
请问这个是哪里出问题了,怎么解决?
解决方案
你第二次使用q_stu_ins_ins时,先清空参数,否则sql中没有,就提示找不到