存储过程中
如果你 output 参数放在 select 行集后面比如
create proc p
(@n int output)
as
select * from tb
select @n=@@rowcount
sqldatareader读取数据时与数据库保持在线连接,即每读一条,还要再读下一条,除非你控制跳出,否则这个@n是得不到的。
可以用datatable来取。也可以改造过程,比如先count赋了值再select行集。
如果你 output 参数放在 select 行集后面比如
create proc p
(@n int output)
as
select * from tb
select @n=@@rowcount
sqldatareader读取数据时与数据库保持在线连接,即每读一条,还要再读下一条,除非你控制跳出,否则这个@n是得不到的。
可以用datatable来取。也可以改造过程,比如先count赋了值再select行集。
数据库传参测试通过 但是用sqldatareader对象保存 输出sqldatareader对象时却总是默认的第一页top@pagesize数据
楼上的内容 我只听懂了一点 你好像说是sqldatareader对象的问题
仔细给我说下好吗
[code]
ALTER procedure [dbo].[proc_turnpage]
(
@pagesize int,
@curpage int,
@condition int
--@count int output
)
as
begin
--select @count=count(*) from note--if(@curpage<1)
--set @curpage=1declare @strsql nvarchar(400)
if(@curpage=1)
begin
set @strsql='select top '+cast(@pagesize as varchar)
+' n.*,u.* from note n left join table_user u on n.uid=u.id '
end
else
begin
set @strsql='select top '+cast(@pagesize as varchar)+
' n.*,u.* from note n left join table_user u on n.uid=u.id where n.id not in(select top '
+cast((@pagesize*(@curpage-1)) as varchar)+' id from note where tid='+cast(@condition as varchar)+
' ) '
end
exec(@strsql)
--exec sp_ExecuteSql @strsql
end
[/code]
(
@pagesize int,
@curpage int,
@condition int
--@count int output
)
as
begin
--select @count=count(*) from note--if(@curpage<1)
--set @curpage=1declare @strsql nvarchar(400)
if(@curpage=1)
begin
set @strsql='select top '+cast(@pagesize as varchar)
+' n.*,u.* from note n left join table_user u on n.uid=u.id '
end
else
begin
set @strsql='select top '+cast(@pagesize as varchar)+
' n.*,u.* from note n left join table_user u on n.uid=u.id where n.id not in(select top '
+cast((@pagesize*(@curpage-1)) as varchar)+' id from note where tid='+cast(@condition as varchar)+
' ) '
end
exec(@strsql)
--exec sp_ExecuteSql @strsql
end
(
@pagesize int,
@curpage int,
@condition int
--@count int output
)
as
begin
--select @count=count(*) from note--if(@curpage<1)
--set @curpage=1declare @strsql nvarchar(400)
if(@curpage=1)
begin
set @strsql='select top '+cast(@pagesize as varchar)
+' n.*,u.* from note n left join table_user u on n.uid=u.id '
end
else
begin
set @strsql='select top '+cast(@pagesize as varchar)+
' n.*,u.* from note n left join table_user u on n.uid=u.id where n.id not in(select top '
+cast((@pagesize*(@curpage-1)) as varchar)+' id from note where tid='+cast(@condition as varchar)+
' ) '
end
exec(@strsql)
--exec sp_ExecuteSql @strsql
end