表的记录在16万左右,存储过程如下:
CREATE procedure kufangChuRuKuReport_KUCUN_bgy
 @FromTime varchar(50),
    @ToTime    varchar(50),
    @czy  varchar(50)
 as 
begin
set nocount on 
             declare @sjcdrq varchar(50)
             select @sjcdrq=convert(varchar(4),year(riqi))+'-'+convert(varchar(2),month(riqi))+'-'+convert(varchar(2),day(riqi))  from kf_wlcundang  where year(riqi)=year(@fromtime) and month(riqi)=month(@fromtime) and (bgybh=@czy)                     select x.kfbh,x.bm,x.gysmc,x.lbjdh,x.lbjmc,x.ggxh,x.dw,x.sfjcj,x.shlx,x.jhjg,qc.QCnum,bin.incount,bout.outcount,(isnull(qc.QCnum,0)+isnull(bin.incount,0)-isnull(bout.outcount,0)) as StoreAmount from  kf_bgyqcsj_view x
left join 
(select kfbh,bm,lbjdh,kcsl as QCnum from kf_wlcundang where (RiQi=@sjcdrq) and (bgybh=@czy) ) qc 
on x.kfbh=qc.kfbh and x.bm=qc.bm and x.lbjdh=qc.lbjdh 
left join 
(select tpind.lbjdh,tpind.bm,tpind.kfbh,
sum(tpind.rksl) as inCount
from kf_billin  tpin  left join kf_billindetail tpind on tpin.rkdh=tpinD.rkdh 
left join kf_bgyqcsj_view  tp1 on tpinD.lbjdh=tp1.lbjdh  and  tpind.bm=tp1.bm  and tpind.kfbh=tp1.kfbh
where (tpin.isfinished=1) and(tpin.rkrq >= @FromTime and  tpin.rkrq <= @ToTime)  and (tp1.bgybh=@czy)
group by tpinD.lbjdh,tpind.bm,tpind.kfbh  ) bin
on x.kfbh=bin.kfbh and x.bm=bin.bm and x.lbjdh=bin.lbjdh
left join 
(select outd.bm,outd.lbjdh,outd.kfbh,
sum(outd.cksl) as outCount
from kf_billout  bout  left join kf_billoutdetail  outd on bout.ckdh=outd.ckdh 
left join kf_bgyqcsj_view  tp1 on outd.lbjdh=tp1.lbjdh  and  outd.bm=tp1.bm  and outd.kfbh=tp1.kfbh
where (bout.isfinished=1) and(bout.ckrq >= @FromTime and  bout.ckrq <= @ToTime) and (tp1.bgybh=@czy)
group by outd.lbjdh,outd.bm,outd.kfbh) bout
on bout.kfbh=x.kfbh and bout.bm=x.bm and bout.lbjdh=x.lbjdh 
where x.bgybh=@czy
order by x.kfbh,x.bm,x.lbjdh set nocount off
end
GOVB调用程序如下:
bomwldy.CommandTimeout = 0
bomwldy.ConnectionTimeout = 0
bomwldy.ConnectionString = kfConnectString
bomwldy.RecordSource = "kufangChuRuKuReport_KUCUN_bgy  '" & DTPicker1.Value & "','" & DTPicker2.Value & "','" & Trim(bgymc) & "'"
bomwldy.Refresh
Set DataGrid1.DataSource = bomwldy
DataGrid1.Refresh

解决方案 »

  1.   

    结果集条数有多少,是不是条数过多导致DATAGRID刷新显示堵塞,而非查询的问题?? 存储过程没有看.
      

  2.   

    结果集也就是700左右条记录,前几天查询都没问题,也就是今天出现这种情况,不知道是SQL有问题,还是系统有问题,总之,VB程序一查询就造成服务器CPU100%,查询不出结果了
      

  3.   

    是服务器的CPU100%啊,这就不会是客户端的DATAGRID显示问题了.
    这种情况一时不好说,你可以逐段逐点来排查.比如,把程序在服务器上运行看看是否还这样,或者干脆新建一个VB工程,只把能运行这个查询的必要代码和引用等加进来,再运行看看.如果都出现这样的问题,就是系统的事,备份数据库之后,卸载再重装,还这样,就把VB也卸载再重装(免得有可能是VB用的数据库驱动程序的问题).
      

  4.   

    也许应顺序颠倒一下,先重装VB吧,感觉数据库可能没问题(SQL查询分析器是用客户端运行的吧).另外也要查下病毒,MSS还是挺容易感染病毒的,会影响网络访问.
      

  5.   

    你用记录集打开查询,然后一个个写到datagrid里,看看会不会出问题.如果不出问题,说明是DATAgrid控件的问题.
      

  6.   

    是服务器CPU100还是客户端100?有可能出现某个数据,使得查询结果过多,把Datagrid弄死了
      

  7.   

    对于相关的表重构建一下索引即可。
    dbcc dbreindex('表名','',80) --80表示填充因子
      

  8.   

    是服务器的CPU100%,有时忽然到达100%,但过一段时间又恢复正常