存取过程使用了暂存的Table,当用VB打开的时候会提示对象已经关闭
编号:QA004382
建立日期: 2001年9月2日 最后修改日期:2001年11月11日
所属类别:
beyond:
操作系统:WIN
编程工具:VB
问题:难题如下:
有存取过程如下:
create proc usp_calc_sex
as
create table #t_sex(
unit char(10) not null,
sex char(10) not null,
r_number int null)
declare @count1 int
declare @count2 int
declare @dept_code varchar(10)
declare @dept_name varchar(20)
declare cur_deptd cursor for
select dept_code,dept_name from t_dept WHERE dept_level = 1 order by dept_code
open cur_deptd
fetch cur_deptd into @dept_code,@dept_name
WHILE (@@fetch_status=0)
begin
select @dept_code = ltrim(rtrim(@dept_code)) +"%"
select @count1=count(*) from t_emp where leave_flag="N" and dept_code like @dept_code and sex="男"
select @count2=count(*) from t_emp where leave_flag="N" and dept_code like @dept_code and sex="女"
insert #t_sex values(@dept_name,"男",@count1)
insert #t_sex values(@dept_name,"女",@count2)
fetch cur_deptd into @dept_code,@dept_name
end
close cur_deptd
deallocate cur_deptd
select @count1=count(*) from t_emp where leave_flag="N" and sex="男"
select @count2=count(*) from t_emp where leave_flag="N" and sex="女"
insert #t_sex values(" 全公司","男",@count1)
insert #t_sex values(" 全公司","女",@count2)
select * from #t_sex
这样的存取过程返回的结果在VB6.0中如何让在DataGrid中显示?请仔细看一下存取过程,它使用了暂存的Table,当您用VB打开的时候,它会提示您对象已经关闭。
回答:
可以把你的存储过程改为如下格式:
create proc usp_calc_sex
as
create table t_sex(
unit char(10) not null,
sex char(10) not null,
r_number int null)
create table #t_sex(
unit char(10) not null,
sex char(10) not null,
r_number int null)
。。。(原来的处理不变)
insert t_sex selecct * from #t_sex
select * from t_sex
drop table t_sex
return
利用以上存储过程建立你的DataGrid,待程序调试完成需要发布时,再将存储过程改为你原来的。注意存储过程名及参数、返回值不能变。
123的意见:
在程序的开头加上
set nocount on
在结果返回前(即最后一条select语句)加上
set nocount off
此问题由shwugen2000回答。
| |
|
|
| |
|
|