各位大虾:
   小的,有条Update语句太长了,不知道如何分割开:
CmdStr:='Update zotheruserlist';
CmdStr:=CmdStr+Format(' Set zusertype=%d,...where zotheruserid=%d',[TypeID,...StrToInt(CarderNo.Text)]);
SQL.Add(CmdStr);
ExecSQL;
请教:怎样把第二条CmdStr:=CmdStr+Format...分成两至三段。。
能不能这么分:
CmdStr:='Update zotheruserlist';
CmdStr:=CmdStr+Format(' Set zusertype=%d,...');
CmdStr:=CmdStr+Format(' Where zotheruserid=%d',[TypeID,...StrToInt(CarderNo.Text)]);
SQL.Add(CmdStr);
ExecSQL;
请教!
我试了,还是不行,最主要的是[TypeID,...StrToInt(CarderNo.Text)]这一部分还有.用两个Format对吗??
请教!!!
各位大虾,小的很很急需解决的!!!

解决方案 »

  1.   

    var
      CmdStr: string;
    begin
      CmdStr := '';
      CmdStr := 'Update zotheruserlist'  CmdStr := CmdStr + Format('Set zusertype=%d,zname=''%s'',zsex=''%s'',zbirthdate=''%s''',[TypeID,Trim(CarderName.Text),Trim(CarderSex.Text),DateToStr(BorthTime.Date)]);  CmdStr := CmdStr+Format('znationality=%d,zbelongtocity=%d,zbelongtozone=%d,zidnumber=''%s'',ztempresid=''%s''', [NationID,ProvinceID,CountyID,Trim(CarderIdentity.Text),Trim(CarderStayed.Text)]);  CmdStr := CmdStr + Format('ztempresexpire=''%s'',zpassportnum=''%s'',zemail=''%s'',zworkingcompany=''%s'',zphonenumber=''%s''',[DateToStr(StayedTime.Date),Trim(CarderPass.Text), Trim(CarderEmail.Text),Trim(CarderUnit.Text),Trim(CarderTel.Text)]);  CmdStr := CmdStr + Format('zcellularnumber=''%s'',zaddress=''%s'',zpostcode=%d Where zotheruserid=%d',[Trim(CarderMobil.Text),Trim(CarderAddress.Text),IntToStr(Trim(CarderMail.Text)),Trim(CarderNo.Text)]);  SQL.text := CmdStr;
    end;
    ------------------------------------------------------------------------------------
    建议看一下delphi帮助中format的用法.
      

  2.   

    To: coeltdit(睫毛上的冰)--非常感谢!
    不过在调试时,还是出错了》在倒数第二条:CmdStr := CmdStr + Format('zcellularnumber=''%s'',zaddress=''%.....
    他的提示是:Project ConsumeApp.exe raise exception class EConvertError with message 'Format'%d'' invalid or incompatible with argument'.
    什么问题,请教,能不能快回!小的急着赶工!!!
      

  3.   

    类型不匹配。你看看
    CmdStr := CmdStr + Format('zcellularnumber=''%s'',zaddress=''%s'',zpostcode=%d Where zotheruserid=%d',[Trim(CarderMobil.Text),Trim(CarderAddress.Text),IntToStr(Trim(CarderMail.Text)),IntToStr(Trim(CarderNo.Text))]);
      

  4.   

    你為什麼一定要用format呢 可以這樣呀
    CmdStr:='Update zotheruserlist'
    CmdStr:=CmdStr+'set zusertype='+#39+TypeID+#39;
      .
      .
      .
    CmdStr:=CmdStr+'where zotheruserid='+#39+TypeID+#39;
    .
    .
    .
    SQL.Add(CmdStr);
      

  5.   

    类型不匹配;
       %s代表string类型;  %d代表Decimal类型;
       CmdStr := CmdStr + Format('zcellularnumber=''%s'',zaddress=''%s'',zpostcode=''%s'' Where zotheruserid=''%s'',[Trim(CarderMobil.Text),Trim(CarderAddress.Text),IntToStr(Trim(CarderMail.Text)),Trim(CarderNo.Text)]);
       把不匹配的%d改为%s试试,要加上''号;
       
      

  6.   

    To:coeltdit(睫毛上的冰):
    不行阿!
    还是出现那种错误。
    我还专把%d的类型放在最后了,都不行。
    怎么解决阿!
    还有什么高招吗??
    请教!
      

  7.   

    要对应, %d对应Decimal类型,%s对应string类型,你一个个的检查,应该没有问题,再有问题给我留言并把SQL语句发给我。