您的位置:程序门 -> vb -> 数据库(包含打印,安装,报表)



请各位高手帮忙!在线等待,分不够我可以加分,以解决问题为主


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


请各位高手帮忙!在线等待,分不够我可以加分,以解决问题为主[已结贴,结贴人:head_skeay]
发表于:2007-08-28 14:57:57 楼主
cmd.commandtext   =   "spu_in_out_qty_report   '2007-03-28 ', '2007-08-28 '   "
cmd.commandtype   =   adcmdtext
cmd.activeconnection   =   gconnection
' ' ' ' ' ' '出现问题部分
set   rs   =   new   adodb.recordset
set   rs   =   cmd.EXECute
' ' ' ' ' ' ' '
类似于这样.上面语句连接都没问题,存储过程在查询分析器能得到数据.
当这样执行能成功
cmd.EXECute
如果我把记录放在一张数据表中通过
set   rs   =   new   adodb.recordset
rs.open   strsql(存储过程数据存放的数据表),   gconnection,   adopenkeyset,   adlockoptimistic
if   not   rs.eof   then
        ' ' '数据
end   if
能处理成功.
但是如果这样就不能.
set   rs   =   new   adodb.recordset
set   rs   =   cmd.EXECute
if   not   rs.eof   then       '运行到此是出现提示   对象关闭时,不允许操作.
        ' ' '数据
end   if

请各位高手帮忙!在线等待,分不够我可以加分,以解决问题为主
发表于:2007-08-28 15:01:101楼 得分:0
我在存储过程中使用的是临时表存储数据的,运行结束后删除了临时表,不过我是先取得记录后删除的,我在查询分析器中是可以查询到记录的.
请问是不是vb在调用存储过程中不能使用比较复杂的语句?
发表于:2007-08-28 15:05:462楼 得分:0
怎么没人来啊,不是这里是技术交流的地方吗?人才了???
发表于:2007-08-28 15:10:223楼 得分:50
没太看懂你说不成功的哪几句不成功。
一般使用存储过程获取数据时,不需要从程序里去查询临时数据表,存储过程中使用的局部临时表在存储过程执行完以后自动就会删除,不需要手动删除。所以不要在执行存储过程后再去访问临时表。
发表于:2007-08-28 15:21:534楼 得分:0
cmd.commandtext   =   "spu_in_out_qty_report   '2007-03-28 ', '2007-08-28 '   "
cmd.commandtype   =   adcmdtext
cmd.activeconnection   =   gconnection
cmd.EXECute
上面的语句能运行成功
但是该成下面的就失败
' ' ' ' ' ' '出现问题部分
cmd.commandtext   =   "spu_in_out_qty_report   '2007-03-28 ', '2007-08-28 '   "
cmd.commandtype   =   adcmdtext
cmd.activeconnection   =   gconnection
cmd.EXECute
set   rs   =   new   adodb.recordset
set   rs   =   cmd.EXECute
if   not   rs.eof   then       '运行到此是出现提示   对象关闭时,不允许操作.
        ' ' '数据
end   if
这个时候我没有把数据存放的临时表中
发表于:2007-08-28 15:23:335楼 得分:0
这是我的存储过程
--       spu_in_out_qty_report '2007-01-29 ', '2007-09-29 '
create       procedure   spu_in_out_qty_report
@start_date     as   varchar(20),
@end_date   as   varchar(20)
as
declare   @strsql   as   varchar(1000)
declare   @strtemptblin     as   varchar(300)
declare   @strtempout     as     varchar(300)
declare   @strtemptblinout   as   varchar(300)

set   @strsql= 'select   *   into   ##temptbin   from   (select   item_id,stock_spec_id,   sum(po_stock_qty*ex_ratio)   as   in_qty  
from   t_po_detail     d   inner   join   t_uom   u   on   d.uom_id=   u.uom_id
where   indate> = ' ' '+@start_date+ ' ' '   and     indate <= ' ' '+@end_date+ ' ' '   group   by   item_id   ,stock_spec_id   )   a '
print   @strsql
EXEC(@strsql)
if   @@error> 0   begin
goto   error
end
set   @strsql= 'select   *   into   ##temptbout   from   (select   item_id,stock_spec_id   ,sum(so_stock_qty*ex_ratio)   as   out_qty  
from   t_so_detail   d   inner   join   t_uom   u   on   d.uom_id=   u.uom_id
where   outdate> = ' ' '+@start_date+ ' ' '   and     outdate <= ' ' '+@end_date+ ' ' '   group   by   item_id   ,stock_spec_id   )   b '
print   @strsql
EXEC(@strsql)
if   @@error> 0   begin
goto   error
end

set   @strsql= 'select   *   into   ##temptbinout   from   (select   a.item_id,a.stock_spec_id,   a.in_qty,a.out_qty  
from   (
select   isnull(ta.item_id,tb.item_id)   as   item_id,isnull(ta.stock_spec_id,tb.stock_spec_id)   as   stock_spec_id,ta.in_qty,tb.out_qty
from   ##temptbin   ta   full   join   ##temptbout   tb   on   ta.item_id=tb.item_id   and   ta.stock_spec_id=tb.stock_spec_id)   a)c '
print   @strsql
EXEC(@strsql)

set   @strsql= 'select   m.part_no,m.full_name,s.stock_spec,isnull(in_qty,0)   as   in_qty,isnull(out_qty,0)   as   out_qty,t.item_id,t.stock_spec_id
from   ##temptbinout   t
inner   join   t_materiel   m   on   t.item_id=m.item_id  
inner   join   t_stock_spec   s   on   t.stock_spec_id=s.stock_spec_id '
print   @strsql
EXEC(@strsql)
if   @@error> 0   begin
goto   error
end
EXEC( 'drop   table   ##temptbin   ')
EXEC( 'drop   table   ##temptbout ')
EXEC( 'drop   table   ##temptbinout ')
goto   error:
go
请帮忙分析问题
发表于:2007-08-28 15:35:366楼 得分:0
我想存储过程应该没问题。
因为在vb里你前面的运行不是已经没问题了么,没试你代码也看不出来有什么问题。
但不知道你可不可以这样写。
你上面的代码都不用了,直接使用gconnection连接的EXECute来执行sql获取数据,直接就将结果给rs就可以了

dim   rs   as   recordset
set   rs   =   gconnection.EXECute( "spu_in_out_qty_report   '2007-03-28 ', '2007-08-28 '   ")
while   not   rs.eof
        从rs中取数
wend
发表于:2007-08-28 15:41:467楼 得分:0
答复楼上

提示错误:对象关闭时,不允许操作.
我就这个郁闷...
都几个星期了,没人能帮我找个解决的办法...
发表于:2007-08-28 15:42:238楼 得分:0
单独运行

gconnection.EXECute( "spu_in_out_qty_report   '2007-03-28 ', '2007-08-28 '   ")

没问题
发表于:2007-08-28 15:44:049楼 得分:0
难道是vb不支持吗?
发表于:2007-08-28 16:16:1510楼 得分:0
cmd.commandtext   =   "spu_in_out_qty_report   '2007-03-28 ', '2007-08-28 '   "
cmd.commandtype   =   adcmdtext
cmd.activeconnection   =   gconnection

你这个时候gconnection是否是打开的?
你为什么不
rs=gconnection.excute   ( "spu_in_out_qty_report   '2007-03-28 ', '2007-08-28 '   ")

发表于:2007-08-28 16:24:2111楼 得分:0
楼上的讲方法都用过结果一样不成功.
gconnection是打开的

这样运行结果一样.
rs=gconnection.excute   ( "spu_in_out_qty_report   '2007-03-28 ', '2007-08-28 '   ")

但是如果我这样运行就可以.why?
create   procedure   spu_test
as  
begin

select   *   from   t_materiel

end  
set   cmd   =   new   adodb.command
cmd.commandtext   =   "spu_test "  
cmd.commandtype   =   adcmdstoredproc
cmd.activeconnection   =   gconnection
set   rs   =   cmd.EXECute
if   not   rs.eof   then     '运行是此出又不出现问题   并且能得到数据
        set   msglist.datasource   =   rs
end   if

由此我觉得vb不支持过多表之间的交互而得到的存储过程.
如果不同意请给个理由,为何我运行不成功.
发表于:2007-08-28 16:45:3412楼 得分:0
你把存储过程改成这样就可以了。
在as下面一行加一句   set   nocount   on
--       spu_in_out_qty_report '2007-01-29 ', '2007-09-29 '
create       procedure   spu_in_out_qty_report
@start_date     as   varchar(20),
@end_date   as   varchar(20)
as
set   nocount   on
declare   @strsql   as   varchar(1000)
declare   @strtemptblin     as   varchar(300)
declare   @strtempout     as     varchar(300)
declare   @strtemptblinout   as   varchar(300)

set   @strsql= 'select   *   into   ##temptbin   from   (select   item_id,stock_spec_id,   sum(po_stock_qty*ex_ratio)   as   in_qty  
from   t_po_detail     d   inner   join   t_uom   u   on   d.uom_id=   u.uom_id
where   indate> = ' ' '+@start_date+ ' ' '   and     indate <= ' ' '+@end_date+ ' ' '   group   by   item_id   ,stock_spec_id   )   a '
print   @strsql
EXEC(@strsql)
if   @@error> 0   begin
goto   error
end
set   @strsql= 'select   *   into   ##temptbout   from   (select   item_id,stock_spec_id   ,sum(so_stock_qty*ex_ratio)   as   out_qty  
from   t_so_detail   d   inner   join   t_uom   u   on   d.uom_id=   u.uom_id
where   outdate> = ' ' '+@start_date+ ' ' '   and     outdate <= ' ' '+@end_date+ ' ' '   group   by   item_id   ,stock_spec_id   )   b '
print   @strsql
EXEC(@strsql)
if   @@error> 0   begin
goto   error
end

set   @strsql= 'select   *   into   ##temptbinout   from   (select   a.item_id,a.stock_spec_id,   a.in_qty,a.out_qty  
from   (
select   isnull(ta.item_id,tb.item_id)   as   item_id,isnull(ta.stock_spec_id,tb.stock_spec_id)   as   stock_spec_id,ta.in_qty,tb.out_qty
from   ##temptbin   ta   full   join   ##temptbout   tb   on   ta.item_id=tb.item_id   and   ta.stock_spec_id=tb.stock_spec_id)   a)c '
print   @strsql
EXEC(@strsql)

set   @strsql= 'select   m.part_no,m.full_name,s.stock_spec,isnull(in_qty,0)   as   in_qty,isnull(out_qty,0)   as   out_qty,t.item_id,t.stock_spec_id
from   ##temptbinout   t
inner   join   t_materiel   m   on   t.item_id=m.item_id  
inner   join   t_stock_spec   s   on   t.stock_spec_id=s.stock_spec_id '
print   @strsql
EXEC(@strsql)
if   @@error> 0   begin
goto   error
end
EXEC( 'drop   table   ##temptbin   ')
EXEC( 'drop   table   ##temptbout ')
EXEC( 'drop   table   ##temptbinout ')
goto   error:
go
发表于:2007-08-28 16:50:4313楼 得分:0
语法
set   nocount   {   on   ¦   off   }

注释
当   set   nocount   为   on   时,不返回计数(表示受   transact-sql   语句影响的行数)。当   set   nocount   为   off   时,返回计数。

即使当   set   nocount   为   on   时,也更新   @@rowcount   函数。

当   set   nocount   为   on   时,将不给客户端发送存储过程中的每个语句的   done_in_proc   信息。当使用   microsoft&reg;   sql   server&#8482;   提供的实用工具执行查询时,在   transact-sql   语句(如   select、insert、update   和   delete)结束时将不会在查询结果中显示 "nn   rows   affected "。

如果存储过程中包含的一些语句并不返回许多实际的数据,则该设置由于大量减少了网络流量,因此可显著提高性能。

set   nocount   设置是在执行或运行时设置,而不是在分析时设置。

发表于:2007-08-29 08:21:5314楼 得分:0
谢谢你,问题果然解决了.


快速检索

最新资讯
热门点击