asp.net 分面控件存储过程改进
2006-03-03 17:12
190 查看
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO
ALTER procedure pt_GetSearchResult
( @TableName NVarChar(100),--表名
@UniqueColumeName NVarChar(100),--表中的ID列名称
@VcharCondiction NVarChar(100), --查询条件
@PageSize int,
@PageIndex int,
@docount bit)
as
--定义变量
declare @cTemp NVarChar(200),@indextable NVarChar(100)
--默认将表的唯一列的列名设置成ID
if @UniqueColumeName =''
set @UniqueColumeName = 'ID'
set nocount on
--得到记录总数
if(@docount=1)
begin
set @cTemp = 'select count(*) from '+@tableName + ' '+ @VcharCondiction
exec (@cTemp)
end
else
--得到结果集
begin
set @indextable = '##temAspPage'
--判断定义的临时表是否已经存在
IF EXISTS(SELECT name FROM tempdb.dbo.sysobjects
WHERE name = @indextable AND type = 'U')
begin
--如果存在 删除临时表
set @cTemp = N' DROP TABLE ' +@indextable
exec (@cTemp)
end
--创建临时表和索引
set @cTemp = N' create table '+@indextable+'(id int identity(1,1),nid int)'+
' CREATE UNIQUE CLUSTERED INDEX indextable_ind ON ' +@indextable +'(id)'
exec (@cTemp)
declare @PageLowerBound int
declare @PageUpperBound int
set @PageLowerBound=(@pageindex-1)*@pagesize
set @PageUpperBound=@PageLowerBound+@pagesize
set rowcount @PageUpperBound
--将符合条件的nid 记录到表里
set @cTemp = 'insert into '+@indextable+'(nid) select newsid from wqnews '+ @VcharCondiction
--print @cTemp
exec (@cTemp)
--将符合条件的结果集显示出来
set @cTemp=' select O.newsid,O.heading,O.source,O.author,O.addtime from wqnews O,'+
@indextable + ' t where O.newsid=t.nid and t.id> '+
cast(@PageLowerBound as varchar) + ' and t.id<= '+
cast(@PageUpperBound as varchar) + ' order by t.id '
print @cTemp
exec (@cTemp)
end
set nocount off
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
dbo.pt_GetSearchResult 'wqnews','newsid','',16,182,0 这么去调用
GO
SET ANSI_NULLS OFF
GO
ALTER procedure pt_GetSearchResult
( @TableName NVarChar(100),--表名
@UniqueColumeName NVarChar(100),--表中的ID列名称
@VcharCondiction NVarChar(100), --查询条件
@PageSize int,
@PageIndex int,
@docount bit)
as
--定义变量
declare @cTemp NVarChar(200),@indextable NVarChar(100)
--默认将表的唯一列的列名设置成ID
if @UniqueColumeName =''
set @UniqueColumeName = 'ID'
set nocount on
--得到记录总数
if(@docount=1)
begin
set @cTemp = 'select count(*) from '+@tableName + ' '+ @VcharCondiction
exec (@cTemp)
end
else
--得到结果集
begin
set @indextable = '##temAspPage'
--判断定义的临时表是否已经存在
IF EXISTS(SELECT name FROM tempdb.dbo.sysobjects
WHERE name = @indextable AND type = 'U')
begin
--如果存在 删除临时表
set @cTemp = N' DROP TABLE ' +@indextable
exec (@cTemp)
end
--创建临时表和索引
set @cTemp = N' create table '+@indextable+'(id int identity(1,1),nid int)'+
' CREATE UNIQUE CLUSTERED INDEX indextable_ind ON ' +@indextable +'(id)'
exec (@cTemp)
declare @PageLowerBound int
declare @PageUpperBound int
set @PageLowerBound=(@pageindex-1)*@pagesize
set @PageUpperBound=@PageLowerBound+@pagesize
set rowcount @PageUpperBound
--将符合条件的nid 记录到表里
set @cTemp = 'insert into '+@indextable+'(nid) select newsid from wqnews '+ @VcharCondiction
--print @cTemp
exec (@cTemp)
--将符合条件的结果集显示出来
set @cTemp=' select O.newsid,O.heading,O.source,O.author,O.addtime from wqnews O,'+
@indextable + ' t where O.newsid=t.nid and t.id> '+
cast(@PageLowerBound as varchar) + ' and t.id<= '+
cast(@PageUpperBound as varchar) + ' order by t.id '
print @cTemp
exec (@cTemp)
end
set nocount off
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
dbo.pt_GetSearchResult 'wqnews','newsid','',16,182,0 这么去调用
相关文章推荐
- 重载asp.net的dropdownlist控件,使其支持样式和空格的一点改进
- 探讨ASP.NET 2.0中的Web控件改进技术(3)
- ASP.NET 自定义WEB控件:DropDownList改进版
- asp.net下Repeater使用 AspNetPager分页控件 不用存储过程 完美实现
- ASP.NET 4.0 之 Menu 控件的改进
- 探讨ASP.NET 2.0中的Web控件改进技术(2)
- asp.net分页控件AspNetPager的使用,使用传统分页和存储过程分页
- 探讨ASP.NET 2.0中的Web控件改进技术(5)
- 一起谈.NET技术,ASP.NET4灵活显标记:数据Web控件改进
- 全面探讨ASP.NET 2.0中的Web控件改进技术之控件设计与模板设计篇(四)
- 探讨ASP.NET 2.0的Web控件改进之概述
- 精进不休 .NET 4.0 (1) - asp.net 4.0 新特性之web.config的改进, ViewStateMode, ClientIDMode, EnablePersistedSelection, 控件的其它一些改进
- asp.net 4.0 新特性之web.config的改进, ViewStateMode, ClientIDMode, EnablePersistedSelection, 控件的其他一些增强点
- ASP.NET,调用存储过程,自动匹配页面控件值与存储过程参数
- [参考]一个ASP.Net的DataGrid分页控件,在Oracle数据库下,每次只取当前页的数据,不使用存储过程
- msdn 数据 Web 服务器 (ASP.NET) 控件
- Asp.Net Ajax--ValidatorCallout控件使用
- ASP.NET Web数据控件
- ASP.NET 數據控件及數據源控件說明