用update修改数据不成功,没有任何提示,帮看看(100分)

  • 主题发起人 主题发起人 yyss
  • 开始时间 开始时间
Y

yyss

Unregistered / Unconfirmed
GUEST, unregistred user!
try<br>&nbsp; F_dm.ADOConnection1.BeginTrans; <br>&nbsp; with adoquery1 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Close;<br>&nbsp; &nbsp; &nbsp; SQL.Clear;<br>&nbsp; &nbsp; &nbsp; SQL.Add('update tb_bmljzs SET bzrs=(select count(*) from tb_main where danwei=:dw and bzcy=:str),bzzs=(select avg(ljzs) from tb_main where danwei=:dw2 and bzcy=:str2) where danwei=:dw3');<br>&nbsp; &nbsp; &nbsp; parameters.ParamByName('dw').Value:=Trim(edit1.Text);<br>&nbsp; &nbsp; &nbsp; parameters.ParamByName('str').Value:='是';<br>&nbsp; &nbsp; &nbsp; parameters.ParamByName('dw2').Value:=Trim(edit1.Text);<br>&nbsp; &nbsp; &nbsp; parameters.ParamByName('str2').Value:='是';<br>&nbsp; &nbsp; &nbsp; parameters.ParamByName('dw3').Value:=Trim(edit1.Text);<br>&nbsp; &nbsp; &nbsp; ExecSql;<br>&nbsp; &nbsp; &nbsp; Close;<br>&nbsp; &nbsp; &nbsp; SQL.Clear;<br>&nbsp; &nbsp; &nbsp; SQL.Add('update tb_bmljzs SET ljrs=(select count(*) from tb_main where danwei=:dw and ljzs&gt;=8),bjlrs=(select count(*) from tb_main where danwei=:dw2 and (ljzs&gt;=6 and ljzs&lt;8)),blrs=(select count(*) from tb_main where danwei=:dw3 and ljzs&lt;6) where danwei=:dw4');<br>&nbsp; &nbsp; &nbsp; parameters.ParamByName('dw').Value:=Trim(edit1.Text);<br>&nbsp; &nbsp; &nbsp; parameters.ParamByName('dw2').Value:=Trim(edit1.Text);<br>&nbsp; &nbsp; &nbsp; parameters.ParamByName('dw3').Value:=Trim(edit1.Text);<br>&nbsp; &nbsp; &nbsp; parameters.ParamByName('dw4').Value:=Trim(edit1.Text);<br>&nbsp; &nbsp; &nbsp; ExecSql;<br>&nbsp; &nbsp; &nbsp; Close;<br>&nbsp; &nbsp; &nbsp; SQL.Clear;<br>&nbsp; &nbsp; &nbsp; SQL.Add('update tb_bmljzs SET sjrs=(select count(*) from tb_main where danwei=:dw and (ljzs&gt;=7 and ljzs&lt;8)),ejrs=(select count(*) from tb_main where danwei=:dw2 and (ljzs&gt;=6 and ljzs&lt;7)) where danwei=:dw3');<br>&nbsp; &nbsp; &nbsp; parameters.ParamByName('dw').Value:=Trim(edit1.Text);<br>&nbsp; &nbsp; &nbsp; parameters.ParamByName('dw2').Value:=Trim(edit1.Text);<br>&nbsp; &nbsp; &nbsp; parameters.ParamByName('dw3').Value:=Trim(edit1.Text);<br>&nbsp; &nbsp; &nbsp; ExecSql;<br>&nbsp; &nbsp; &nbsp; Close;<br>&nbsp; &nbsp; &nbsp; SQL.Clear;<br>&nbsp; &nbsp; &nbsp; SQL.Add('update tb_bmljzs SET yjrs=(select count(*) from tb_main where danwei=:dw and ljzs&lt;6) where danwei=:dw2');<br>&nbsp; &nbsp; &nbsp; parameters.ParamByName('dw').Value:=Trim(edit1.Text);<br>&nbsp; &nbsp; &nbsp; parameters.ParamByName('dw2').Value:=Trim(edit1.Text);<br>&nbsp; &nbsp; &nbsp; ExecSql;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; F_dm.ADOConnection1.CommitTrans; &nbsp; <br>&nbsp;except<br>&nbsp; &nbsp;F_dm.ADOConnection1.RollbackTrans; &nbsp; &nbsp; <br>&nbsp;end;
 
请仔细检查 where 子句,估计是没有符合子句条件的记录。
 
你一下全贴上来了.你可以一步步的提交测试啊.看是那部份的问题.另外用MS的那个数据库跟踪工具看一下就OK了.问题太简单,要是还搞不定,在开一个三百的贴我给你搞定算了.......
 
第一个是看参数传得是否正确<br>第二个是看下把你的SQL语句UPDATE扔到查询分析器里去执行下试试。。。<br>第三个是用跟踪器看一下SQL语句的执行情况。。。
 
分析器、探查器都没有看出什么原因
 
建议你先把SQL简化,然后再逐步添加,一步一步查看哪出了问题。
 
在查询分析器中试一下你的UPDATE
 
建议简化SQL,并用查询分析器测试其SQL语句
 
我想问题出在sql语句赋值上,好像不能这样赋值。简化如下:<br>with adoquery1 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Close;<br>&nbsp; &nbsp; &nbsp; SQL.Clear;<br>&nbsp; &nbsp; &nbsp; SQL.Add('update tb_bmljzs SET bzrs=(select count(*) from tb_main where danwei=:dw) where danwei=''a''');<br>&nbsp; &nbsp; &nbsp; parameters.ParamByName('dw').Value:=Trim(edit1.Text);<br>&nbsp; &nbsp; &nbsp; ExecSql;<br>&nbsp; &nbsp;end;
 
试试<br>bzrs=(select count(*) as a from tb_main where danwei=:dw)
 
在ExecSql;之前设断点把SQL语句 放到查询分析器里执行 问题就很简单了
 
都是经验之谈啊!<br><br>在查询分析器里执行,如果也没报错,就很可能是你对表做了触发器了啊<br><br>得不到正确的结果
 
帮顶. <br><br>ASP,DELPHI,PB,VB 极具价值的233套大型商业源代码出售. 总共5.10G,仅售100元,<br>预购请联系QQ: 505042586 &nbsp;阿里旺旺:zymyjl
 
后退
顶部