SQLServer 插入记录报错


begin
          RzProgressStatus1.Percent:=0;
          s1:='';
          for i2:=1 to mylist.Count do
          begin
            //rid1:=IntToStr(i2+1);
            rid1:= IntToStr(i2);
            RzProgressStatus1.Percent:=50*i2 div i1 ;
            s2:= QuotedStr(Utf8Decode(mylist[i2-1]));
            //s1:=s1+'insert into CUXIAOINFO (P_ID,G_ID,R_ID,DATE) values('+bagid+','+s2+','+rid1+') ';
            s1:=s1+'insert into CUXIAOINFO (R_ID,P_ID,G_ID) values('+rid1+','+bagid+','+s2+') ';
          end;
          con1.Open;
          con1.BeginTrans;
          cmd1.CommandText:=s1;
          cmd1.Execute();
          con1.CommitTrans;
          RzStatusPane2.Caption:= 'Êý¾Ýµ¼Èë³É¹¦£¡';
          RzProgressStatus1.Percent:=100;
          Time:=(GetTickCount-Time);
          MsgStr:=Format('ÓÃʱ %d ºÁÃë',[Time]);
          ShowMessage(MsgStr);

        end ;

用ADO连接SQLServer, 字符串bagid如果是全数字,没问题,一旦出现非数字字符串,就报告附近有语法错误,不明白是什么问题。反倒是字符串s2就没问题,难道对bagid字符串用 QuotedStr函数处理?但是这个函数只是解决汉字乱码的问题啊。字段P_ID,G_ID都是nchar类型,到底是什么问题啊?

还是字符串处理问题,真的需要对bagid字符串用 QuotedStr函数处理!唉!

建议用delphi2005+,支持unicude,识别中文字符串