存储错误:例外詳細資訊: 沒有包含任何資料來源。

jxjjljf 2006-01-20 07:18:56
作者:过客 存储错误:例外詳細資訊: 沒有包含任何資料來源。
CREATE proc page
@pageIndex int, --页数
@pageSize int, --页面显示的数据量
@sql1 NVarChar (500),
@sql2 NVarChar (500),
@sql3 NVarChar (500)
as
declare @strSql varchar(5000) --查询的Sql语句
declare @strSql2 varchar(5000) --查询条件的Sql语句

if @pageIndex = '1'
set @strSql='select top' + str(@pageSize) + + '* from pur where p_id!='''''
else
begin
set @strSql = 'select top' + str(@pageSize) + + '* from pur'
set @strSql = @strSql + ' ' + 'where p_id <('
set @strSql = @strSql + 'select min(p_id) from ('
set @strSql = @strSql + 'select top '+ str((@pageIndex-1)*@pageSize) + +' p_id from pur
where p_id!='''''+@strSql2+'order by p_id desc) as t' +') '
end

if @sql1 is null or @sql1=''
set @strSql2 = @strSql2 + ''
else
if @sql1=7
begin
set @strSql2 = @strSql2 +' '+ 'and status <> 5'
end
else
begin
set @strSql2 = @strSql2 +' '+ 'and status='+str(@sql1)
end

if @sql2 is not null and @sql2 <> ''
begin
if @sql3 is not null and @sql3 <> ''
begin
set @strSql2 = @strSql2 +' '+'and indate between'''+cast(@sql2 as NVarChar)+'''' + 'and'''+cast(@sql3 as NVarChar)+''''
end
else
begin
set @strSql2 = @strSql2 +' '+'and indate='''+cast(@sql2 as NVarChar)+''''
end
end

set @strSql = @strSql + @strSql2

set @strSql = @strSql +' '+'order by p_id desc'

exec(@strSql)
GO

如果把这句去掉set @strSql = @strSql + @strSql2
就可以,但现在的问题是我要连接这个条件@strSql2
否则传入的条件不能接上去
...全文
63 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
nimeide1234567890 2006-01-21
  • 打赏
  • 举报
回复
CREATE proc page
@pageIndex int, --页数
@pageSize int, --页面显示的数据量
@sql1 NVarChar (500),
@sql2 NVarChar (500),
@sql3 NVarChar (500),
@strSql4 NVarChar (500)=''
as
declare @strSql varchar(5000) --查询的Sql语句

if @sql1 is null or @sql1='' --条件一
set @strSql4 = @strSql4 + ''
else
if @sql1=7
begin
set @strSql4 = @strSql4 +' '+ 'and status <> 5'
end
else
begin
set @strSql4 = @strSql4+' '+ 'and status='+str(@sql1)
end

if @sql2 is not null and @sql2 <> '' --条件二
begin
if @sql3 is not null and @sql3 <> ''
begin
set @strSql4 = @strSql4 +' '+'and indate between'''+cast(@sql2 as NVarChar)+'''' + 'and'''+cast(@sql3 as NVarChar)+''''
end
else
begin
set @strSql4 = @strSql4 +' '+'and indate='''+cast(@sql2 as NVarChar)+''''
end
end

if @pageIndex = '1'
set @strSql='select top' + str(@pageSize) + ' ' + '* from pur where id!='''''+@strSql4
else
begin
set @strSql = 'select top' + str(@pageSize) + + '* from pur'
set @strSql = @strSql + ' ' + 'where id!='''''+@strSql4+' '+'and id <('
set @strSql = @strSql + 'select min(id) from ('
set @strSql = @strSql + 'select top '+ str((@pageIndex-1)*@pageSize) + +' id from pur where id!='''''+@strSql4+' '+' order by id desc) as t' +') '
end


set @strSql = @strSql +' '+'order by indate desc,pono desc'
--print(@strSql)
exec(@strSql)
GO
jxjjljf 2006-01-20
  • 打赏
  • 举报
回复
@pageIndex int, --页数 2
@pageSize int, --页面显示的数据量 10
@sql1 NVarChar (500), 没填
@sql2 NVarChar (500), 没填
@sql3 NVarChar (500), 没填
@sql4 NVarChar (500) and status='0'

select top 10* from pur where id <(select min(id) from (select top 10 id from pur where id!='' and status='0' order by id desc) as t) and status='0' order by id desc
这样在数据库里选出了10条数据,但点下一页的时候还是数据没变化
jxjjljf 2006-01-20
  • 打赏
  • 举报
回复
每当从数据库里最新的一条数据(没有任何条件)开始分页那么每页都可以显示不同的数据
如果从其他的ID(条件)开始,那么就可能老是显示同一页的数据

set @strSql = 'select top' + str(@pageSize) + + '* from pur'
set @strSql = @strSql + ' ' + 'where p_id <('
set @strSql = @strSql + 'select min(p_id) from ('
set @strSql = @strSql + 'select top '+ str((@pageIndex-1)*@pageSize) + +' p_id from pur
where p_id!='''''+@strSql2+'order by p_id desc) as t' +') '
我想就是这句错了,请教
qw_zr 2006-01-20
  • 打赏
  • 举报
回复
你没填当然出错了!
jxjjljf 2006-01-20
  • 打赏
  • 举报
回复
@pageIndex int, --页数 2
@pageSize int, --页面显示的数据量 10
@sql1 NVarChar (500), 没填
@sql2 NVarChar (500), 没填
@sql3 NVarChar (500) 没填

SELECT TOP 10 *
FROM Pur
WHERE (id <
(SELECT MIN(id)
FROM (SELECT TOP 10 id
FROM pur
WHERE p_id != ''
ORDER BY id DESC) AS t))
ORDER BY id DESC
这样在数据库里选出了10条数据,但点下一页的时候数据没变化
qw_zr 2006-01-20
  • 打赏
  • 举报
回复
@pageIndex int, --页数
@pageSize int, --页面显示的数据量
@sql1 NVarChar (500),
@sql2 NVarChar (500),
@sql3 NVarChar (500)

这些输入参数是多少,你把你的实验数据写一下。

62,039

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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