表裏有50個字段,我寫insert語句,執行成功 ,也不報錯!但是居然後臺數據庫不能插入記錄!
有人遇到過這種情況嗎??是什麽原因?
高手指點,要代碼的時候,我再發代碼1

解决方案 »

  1.   

    50个字段?我的天,还真没试过不知道sql支不支持那么长的sqlstring
      

  2.   

    应该是你的代码有错误了,如果真插入不了,可以select @@Error,看看错误号对应的消息
      

  3.   

    时空系列产品(GSP),表的字段有的达75个以上,而且字段的命名都是和汉字有关,分声母,韵母,繁得不能再繁了
      

  4.   

    应该是重复记录或者索引问题如果你通过SQL模式插入,很多时候Delphi是没有任何提示的,但是数据可能是无效的,所以不能插入。先拷贝一个临时表出来,然后往临时表里添加记录看看是否可以,否则就是数据的问题
      

  5.   

    謝謝大家關注!
    現在貼代碼!就是很簡單的查詢后加入~~
    提示也是 執行成功!
        with datam.adoqll003 do
    begin
    close;
    sql.Clear;
    sql.Add('begin tran');
    sql.Add('declare @goodsid int,@gdtypeid int,@csubid int,@esubid int,@isubid int,@ssubid int,@kind int,@cancmb int,@closed int,@cbcal int,');
    sql.Add('@recbcal int,@psubid int,@dsubid int,@recbcalbillid int,@mrpcal int,@prequest int,@paheaddays int,@bomsourceid int,@vendorid int,');
    sql.Add('@wsubid int,@rebuild int,@depid int,@goodsdepid int,@code varchar(64),');
    sql.Add('@name varchar(64),@memorycode varchar(64),@barcode varchar(64),@memcode varchar(64),@unit varchar(64),@spec varchar(64),');
    sql.add('@description varchar(64),@re1 varchar(64),@re2 varchar(64),@re3 varchar(64),@engname varchar(64),@engpartcode varchar(64),');
    sql.Add('@engtariffcode varchar(64),@engre varchar(64),@abc varchar(64),@topqty float,@downqty float,@pprice float,@sprice1 float,@sprice2 float,@sprice3 float,@sprice4 float,@sprice5 float,');
    sql.Add('@aprice float,@lpprice float,@lsprice float,@toppprice float,@downsprice float,@downaprice float,@topaprice float,@recbcaldate datetime');
    sql.Add('select @goodsid=goodsid,@gdtypeid=gdtypeid,@csubid=csubid,@esubid=esubid,@isubid=isubid,');
    sql.Add('@ssubid=ssubid,@kind=kind,@cancmb=cancmb,@closed=closed,@cbcal=cbcal,@recbcal=recbcal,');
    sql.add('@psubid=psubid,@dsubid=dsubid,@recbcalbillid=recbcalbillid,@mrpcal=mrpcal,@prequest=prequest,');
    sql.Add('@paheaddays=paheaddays,@bomsourceid=bomsourceid,@vendorid=vendorid,@wsubid=wsubid,');
    sql.Add('@rebuild=rebuild,@depid=depid,@goodsdepid=goodsdepid,@code=code,@name=name,');
    sql.add('@memorycode=memorycode,@barcode=barcode,@memcode=memcode,@unit=unit,@spec=spec,@description=description,@re1=re1,');
    sql.Add('@pprice=pprice,@sprice1=sprice1,@sprice2=sprice2,@sprice3=sprice3,@sprice4=sprice4,@sprice5=sprice5,@aprice=aprice,@lpprice=lpprice,');
    sql.Add('@re2=re2,@re3=re3,@engname=engname,@engpartcode=engpartcode,@engtariffcode=engtariffcode,@engre=engre,@abc=abc,');
    sql.Add('@topqty=topqty,@downqty=downqty,@lsprice=lsprice,@toppprice=toppprice,@downsprice=downsprice,@downaprice=downaprice,@topaprice=topaprice,@recbcaldate=recbcaldate');
    sql.add('from DB1..goods where code='aaa');sql.Add('insert into DB2..goods (goodsid,gdtypeid,csubid,esubid,isubid,ssubid,kind,cancmb,closed,');
    sql.Add('cbcal,recbcal,psubid,dsubid,recbcalbillid,mrpcal,prequest,paheaddays,');
    sql.add('bomsourceid,vendorid,wsubid,rebuild,depid,goodsdepid,code,name,memorycode,barcode,memcode,');
    sql.add('unit,spec,description,re1,re2,re3,engname,engpartcode,engtariffcode,engre,abc,');
    sql.Add('topqty,downqty,pprice,sprice1,sprice2,sprice3,sprice4,sprice5,aprice,lpprice,lsprice,toppprice,');
    sql.Add('downsprice,downaprice,topaprice,recbcaldate)');
    sql.add('values (@goodsid,@gdtypeid,@csubid,@esubid,');
    sql.add('@isubid,@ssubid,@kind,@cancmb,@closed,@cbcal,@recbcal,@psubid,@dsubid,@recbcalbillid,@mrpcal,');
    sql.add('@prequest,@paheaddays,@bomsourceid,@vendorid,@wsubid,@rebuild,@depid,@goodsdepid,@code,@name,');
    sql.add('@memorycode,@barcode,@memcode,@unit,@spec,@description,@re1,@re2,@re3,@engname,');
    sql.add('@engpartcode,@engtariffcode,@engre,@abc,@topqty,@downqty,@pprice,@sprice1,@sprice2,@sprice3,');
    sql.add('@sprice4,@sprice5,@aprice,@lpprice,@lsprice,@toppprice,@downsprice,@downaprice,@topaprice,@recbcaldate)');
    sql.add('if @@error<>0');
    sql.Add('rollback tran');
    sql.Add('else');
    sql.add('commit tran');
    execsql; 
    showmessage('執行成功!');
    説明:我是從一個庫裏查詢,加入另外一個庫,就是複製!如果大家覺得這個方法不好,提出新的方法也可以!真的很鬱悶,字段少的情況下,我試過,是可以的!
    高手指點!
      

  6.   

    昏迷…这么长的SQL,估计delphi不能认识了~~~~
    另外弱弱的提醒下,select ,from ,values 等等关键字是要空格分开的吧,楼主会不会在串字串的时候,没有注意空格啊?
      

  7.   

    1、你的做法是不可能跟踪出问题的,因为你启用了数据库的事务处理,而且已经进行了事务判断及回滚功能2、应该首先把事务部分去掉再执行,看Delphi的前台提示信息是什么3、如果前台没有信息,通过数据库的跟踪功能看看你到底执行的是什么SQL语句,然后把这些语句在SQL中直接执行再去看结果,记得也要去调事务部分代码
    *事务是好,但是当你的数据库比较大而且要多表运算的时候那是相当的慢
      

  8.   

    50个字段还不用存储过程,干吗在前台组织那么长的sql。