仅显示最新数据....... [英] Display Only Latest Data.......

查看:50
本文介绍了仅显示最新数据.......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



i想要只显示10或20等最新数据......在gridview中



如果我点击更多,那么它应该显示更多记录。



喜欢facebook。

在Facebook上它只加载最新评论,但如果你进入底部然后点击更多它将显示更多评论,

hi folks,

i want to display only latest data like 10 or 20....in gridview

if i click on more then it should display more records.

like facebook.
in facebook it loads only latest comments, but if you go in bottom then click more it will display more comments,

推荐答案

嗨请检查以下查询



hi Please check below query

Create PROCEDURE [dbo].[tblProductSelectByCatalogid] (
		@StrSortBy varchar(50)='Coumn name',
		@StrSortOrder varchar(50)='ASC/DESC',
		@intPageNum int=1,
		@intPageSize int=10,
)
AS

SET NOCOUNT ON

declare @SQL nvarchar(max)
Declare @Condition nvarchar(max)  
DECLARE @strSQLCount VARCHAR(MAX)
DECLARE @strFinalSQL VARCHAR(MAX)


SET @Condition = ''  



set @SQL ='
SELECT * FROM [tablename] WHERE Condition'

SET @SQL = @SQL + @Condition  



IF @intPageSize <> 0
	BEGIN
		SET @strFinalSQL = ' SELECT * FROM ('
		SET @strFinalSQL = @strFinalSQL + ' Select Row_Number() OVER (Order by ' + @StrSortBy + ' ' + @StrSortOrder + ') As RowNum,*  From( ' 
		SET @strFinalSQL = @strFinalSQL + @SQL
		SET @strFinalSQL = @strFinalSQL + ' )T )T1 ' 
		SET @strFinalSQL = @strFinalSQL + ' Where RowNum BETWEEN ' + Cast((@intPageNum - 1) * @intPageSize + 1 as varchar(5)) + ' AND ' + Cast(@intPageNum * @intPageSize as varchar(5)) 
	END
	ELSE
	BEGIN
			--SET @strFinalSQL = @SQLQuery
	SET @strFinalSQL = ' Select Row_Number() OVER (Order by ' + @StrSortBy + ' ' + @StrSortOrder + ') As RowNum,*  From( ' 
	SET @strFinalSQL = @strFinalSQL + @SQL
	SET @strFinalSQL = @strFinalSQL + ' )T'
	END

	EXEC (@strFinalSQL)
		print(@strFinalSQL)

	SET @strSQLCount = ' Select Count(*) as intTotalRecords  From( '
	SET @strSQLCount = @strSQLCount + @SQL
	SET @strSQLCount = @strSQLCount + ' )T'
	Exec (@strSQLCount)





在上面的查询中你可以看到我们传递的页面没有和页面大小

如果我们传递第1页和大小等于10然后首先它将需要10个记录

下次我们将页面号增加到2然后程序将返回11-20记录像智者。



你可以通过设置Pagesize和页面编号为你提供组合。



希望这会有所帮助:)



in above query you can see that we pass the page no and page size
if we pass page no 1 and size equal to 10 then first it will take 10 record
next time we will increase page no to 2 then procedure will return 11-20 record like wise.

you can provide you combination by setting the Pagesize and page no.

Hope this will help :)


请在网格视图中使用 Pagging 概念显示数据10,20,30或....



要在Gridview中显示最新记录,您需要 使用主键字段 并使用 ORDER BY 降序
Please use Pagging concept in grid view for display data 10,20,30 or ....

To display latest record in Gridview for that you need to use primary key field and use ORDER BY with descending order.


您好RealSoftBardoli

1)添加序列号列并使其标识为true或在数据库中添加日期列。

2)如果您添加序列号然后只获得MAX(SERIAL_NUMBER),如果您添加日期列,则使用MAX(日期)



你肯定会得到结果。
Hi RealSoftBardoli
1)Either add a serial number column and make its identity true Or add date column in your database.
2)If you add Serial number then just get MAX(SERIAL_NUMBER) and if you add Date Column then use MAX(DATE)

You will get the result,for sure.


这篇关于仅显示最新数据.......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆