这里有注释的地方,赋值部分我需要从另外一个表里读出来,比如!Parameters.ParamByName('InpDep').Value:=StrGrInport.Cells[8,i]; 这里的 StrGrInport.Cells[8,i]我需要从另外一个表里读出来另外的一个值来代替,如select id from oinfo where sname = StrGrInport.Cells[8,i]. 这里如何写? access数据库!! 帮我写一句!谢谢
如下:sql.Add('insert into stainfo(stano,sname,sex,birth,tel,mobile,email,depid,sorts,duty,provi,folk,level,special,cardno,recno,politics,slevel,married,indate,dutystate,dutydate,stadate,leftdate,baryear,barstart,barend,school,gradate,body,address,pcode,des)'+
'values(:InpStano,:InpSname,:InpSex,:InpBirth,:InpTel,:InpMobile,:InpEmail,:InpDep,:InpSorts,:InpDuty,:InpProvi,:InpFolk,:InpLev,:InpSpec,:InpCardno,:InpRecno,:InpPolitics,:InpSlevel,:InpMarried,:InpIndate,'+
':InpDutyState,:InpDutyDate,:InpStaDate,:InpLeftDate,;InpBaryYear,;InpBarStart,:InpBarEnd,:InpSchool,:InpGraDate,:InpBody,:InpAddress,:InpPcode,:InpDes)'); Parameters.ParamByName('InpStano').Value:=strgrinport.Cells[1,i];....... Parameters.ParamByName('InpDep').Value:=StrGrInport.Cells[8,i]; //数字,要读取其他表获得
Parameters.ParamByName('InpSorts').Value:=StrGrInport.Cells[9,i]; //数字,要读取其他表获得
Parameters.ParamByName('InpDuty').Value:=StrGrInport.Cells[10,i]; //数字,要读取其他表获得
Parameters.ParamByName('InpProvi').Value:=StrGrInport.Cells[11,i];
Parameters.ParamByName('InpFolk').Value:=StrGrInport.Cells[12,i]; //数字,要读取其他表获得
Parameters.ParamByName('InpLev').Value:=StrGrInport.Cells[13,i]; //数字,要读取其他表获得
Parameters.ParamByName('InpSpec').Value:=StrGrInport.Cells[14,i]; //数字,要读取其他表获得
.......ExecSQL;
Close;
如下:sql.Add('insert into stainfo(stano,sname,sex,birth,tel,mobile,email,depid,sorts,duty,provi,folk,level,special,cardno,recno,politics,slevel,married,indate,dutystate,dutydate,stadate,leftdate,baryear,barstart,barend,school,gradate,body,address,pcode,des)'+
'values(:InpStano,:InpSname,:InpSex,:InpBirth,:InpTel,:InpMobile,:InpEmail,:InpDep,:InpSorts,:InpDuty,:InpProvi,:InpFolk,:InpLev,:InpSpec,:InpCardno,:InpRecno,:InpPolitics,:InpSlevel,:InpMarried,:InpIndate,'+
':InpDutyState,:InpDutyDate,:InpStaDate,:InpLeftDate,;InpBaryYear,;InpBarStart,:InpBarEnd,:InpSchool,:InpGraDate,:InpBody,:InpAddress,:InpPcode,:InpDes)'); Parameters.ParamByName('InpStano').Value:=strgrinport.Cells[1,i];....... Parameters.ParamByName('InpDep').Value:=StrGrInport.Cells[8,i]; //数字,要读取其他表获得
Parameters.ParamByName('InpSorts').Value:=StrGrInport.Cells[9,i]; //数字,要读取其他表获得
Parameters.ParamByName('InpDuty').Value:=StrGrInport.Cells[10,i]; //数字,要读取其他表获得
Parameters.ParamByName('InpProvi').Value:=StrGrInport.Cells[11,i];
Parameters.ParamByName('InpFolk').Value:=StrGrInport.Cells[12,i]; //数字,要读取其他表获得
Parameters.ParamByName('InpLev').Value:=StrGrInport.Cells[13,i]; //数字,要读取其他表获得
Parameters.ParamByName('InpSpec').Value:=StrGrInport.Cells[14,i]; //数字,要读取其他表获得
.......ExecSQL;
Close;
解决方案 »
- Delphi报表问题?
- 急、急、急:怎样设置TreeView的根为不可拖动的?
- 谁有比较详细的二进制文件的读写实例啊?
- ORACLE OLEDB如何通过Stored procedure取得结果集?
- 不常见的问题哦!(DBGrid1DrawColumnCell,AfterScroll,DataSource1DataChange哪个快?)
- 那位老大帮一下啊!!(在线等!!!)
- 如何实现双击表格中的某条记录时,弹出对话框修改该条记录的内容?
- 请问那里有这本书下载,delphi developer's guide to opengl,10分钟结账
- 一个遍历文件和目录的问题~~怎么总有.和..呢?
- 新手,该选哪本DELPHI??谢谢了!!
- delphi中把excel的数据逐条导入到数据库中的问题
- 字符相加问题
Open; 你查询分析器里怎么写,Delphi里就生成什么语句执行
sql.text:='select [id] from ointo where sname='''+trim(StrGrInport.Cells[8, i])+'''';
怎么弄? 检索出(StrGrInport.Cells[8, i])没问题,但是如何赋给 Parameters.ParamByName('InpDep').Value ,问题很大啊!! 敬请指点~~
begin
Parameters.ParamByName('InpDep').asfloat:=strtofloat(StrGrInport.Cells[8,i]);
//-----如果字段类型是:numeric(12,4)这样的类型的;
Parameters.ParamByName('InpDep').asstring:=trim(StrGrInport.Cells[8,i]);
//-----如果字段类型是:varchar(12)这样的类型的;end;
我好象没说清楚!!!我是想用 StrGrInport.Cells[8,i]这个值来做条件,检索另外一个表里的ID号,而不是直接把StrGrInport.Cells[8,i]格式转化!!我需要的是 类似如下的代码:
insert into stainfo (stano,sname,sex)values([select id from oinfo where sname='+StrGrInport[8,i]+'],:InpSname,:InpSex)
SQL Script:
delclare @sid varchar(24)
set @sid=(select [id] from oinfo where sname=@sname)
insert into stainfo (stano,sname,sex)
values(@sid,@InpSname,@InpSex)