[存储过程]求救:我的存储过程不能将RETURN值返回给前台程序(VB写的)!十万火急

PI_2002 2002-09-05 07:00:32
我试了的,存储过程中的语句都能执行,返回值(@@ROWCOUNT)也是对的,但是前台的VB程序可以使用返回的记录集,而接受不到RETURN的返回值。(也不报错)

这个存储过程的目的主要是将分类统计的结果以数据集的形式返回给前台程序,同时返回这个记录集的总数。

我的存储过程如下:

use bjdb
if exists (select name from sysobjects where name = 'p_tj_zby' and type ='P')
drop procedure p_tj_zby
go
create procedure p_tj_zby
@m_ssj datetime, --开始时间
@m_esj datetime --借助
as
declare @lbx int
select t_main.zby,count(t_main.zby) as cjsl
from t_main
where t_main.zby in (select t_man.xm from t_man where t_man.lvl > 1) and (t_main.jjsj between @m_ssj and @m_esj)
group by t_main.zby
--按给定的时间产生工作数量;
set @lbx = @@rowcount
return @lbx
GO
...全文
108 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Yang_ 2002-09-05
  • 打赏
  • 举报
回复
关键是调用方法:
看一下测试情况:

存储过程(和你得很象吧):
create proc proc_test1
@id int
as
declare @cn int
select * from b where id=@id
set @cn=@@rowcount
return @cn
go

在产分析器调用正常
declare @r int
exec @r=proc_test1 1
select @r as returnvalue


VB调用方法:

Dim rs As ADODB.Recordset
Dim returnvalue As Long
Dim rs1 As ADODB.Recordset

Set rs = con.Execute("declare @r int exec @r=proc_test1 1 select @r as returnvalue")

Set rs1 = rs.NextRecordset
returnvalue = rs1!returnvalue '在这里取返回值
Print returnvalue

Set DataGrid1.DataSource = rs '存储过程的记录集在rs里


PI_2002 2002-09-05
  • 打赏
  • 举报
回复
请问:N_chow() ,BluePig(吹猪)

一个存储过程里面有两条SELECT语句,那么前端用RECORDSET接收,会接收到哪一个呢?
AWP365 2002-09-05
  • 打赏
  • 举报
回复
两种办法
1使用Command对象,param定义为output
2return 改为 select ,前端使用recordset
murphy711 2002-09-05
  • 打赏
  • 举报
回复
create procedure p_tj_zby
@m_ssj datetime, --开始时间
@m_esj datetime, --借助
@lbx int output --输出值
as
declare @lbx int
select t_main.zby,count(t_main.zby) as cjsl
from t_main
where t_main.zby in (select t_man.xm from t_man where t_man.lvl > 1) and (t_main.jjsj between @m_ssj and @m_esj)
group by t_main.zby
--按给定的时间产生工作数量;
set @lbx = @@rowcount
GO
newly_ignorant 2002-09-05
  • 打赏
  • 举报
回复
UP
1、Command的Return字段
2、定义输出参数
N_chow 2002-09-05
  • 打赏
  • 举报
回复
要接收Stored procedure返回的值,則要用Command對象。
你這種情況,或者可以這樣。
create procedure p_tj_zby
@m_ssj datetime, --开始时间
@m_esj datetime --借助
as
declare @lbx int
set nocount on
select t_main.zby,count(t_main.zby) as cjsl
from t_main
where t_main.zby in (select t_man.xm from t_man where t_man.lvl > 1) and (t_main.jjsj between @m_ssj and @m_esj)
group by t_main.zby
--按给定的时间产生工作数量;
select @@rowcount as cnt

GO
前端用Recordset來接收就好了 。

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧