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

解决方案 »

  1.   

    SQL.Text := Format('select id from oinfo where sname = %s', [QuotedStr(StrGrInport.Cells[8, i])]);
    Open; 你查询分析器里怎么写,Delphi里就生成什么语句执行
      

  2.   

    算了,还是捡些分算了。 ^___^
    sql.text:='select [id] from ointo where sname='''+trim(StrGrInport.Cells[8, i])+'''';
      

  3.   

    楼上两位老大,我主要还要把获得的这个值赋给 Parameters.ParamByName('InpDep').Value 啊!! 
    怎么弄? 检索出(StrGrInport.Cells[8, i])没问题,但是如何赋给 Parameters.ParamByName('InpDep').Value  ,问题很大啊!! 敬请指点~~
      

  4.   

    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;
      

  5.   

    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)
      

  6.   

    我只给你写出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)