天下之大,无奇不有!有答就有分

blueflag 2006-10-31 02:47:07
这里有注释的地方,赋值部分我需要从另外一个表里读出来,比如!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;

...全文
248 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
小呆之家 2006-11-02
  • 打赏
  • 举报
回复
-_-# -_-!!
blueflag 2006-11-02
  • 打赏
  • 举报
回复
辣椒 好人!!

我咋没想起来用游标!!!!
小呆之家 2006-11-01
  • 打赏
  • 举报
回复
我只给你写出SQL代码,其他的东西你自己想想,通过参数的方法其实是可以实现的。
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)
blueflag 2006-11-01
  • 打赏
  • 举报
回复
TO ,辣椒
我好象没说清楚!!!

我是想用 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)


springlie 2006-10-31
  • 打赏
  • 举报
回复
我还是接分闭嘴好了
早起晚睡 2006-10-31
  • 打赏
  • 举报
回复
JF
spirit_sheng 2006-10-31
  • 打赏
  • 举报
回复
接分
小呆之家 2006-10-31
  • 打赏
  • 举报
回复
if trim(StrGrInport.Cells[8,i])>'' then
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;
blueflag 2006-10-31
  • 打赏
  • 举报
回复
顶上去~~~~~~
blueflag 2006-10-31
  • 打赏
  • 举报
回复
楼上两位老大,我主要还要把获得的这个值赋给 Parameters.ParamByName('InpDep').Value 啊!!
怎么弄? 检索出(StrGrInport.Cells[8, i])没问题,但是如何赋给 Parameters.ParamByName('InpDep').Value ,问题很大啊!!

敬请指点~~
小呆之家 2006-10-31
  • 打赏
  • 举报
回复
算了,还是捡些分算了。 ^___^
sql.text:='select [id] from ointo where sname='''+trim(StrGrInport.Cells[8, i])+'''';
王集鹄 2006-10-31
  • 打赏
  • 举报
回复
SQL.Text := Format('select id from oinfo where sname = %s', [QuotedStr(StrGrInport.Cells[8, i])]);
Open;

你查询分析器里怎么写,Delphi里就生成什么语句执行

2,497

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧