如果我们选择了上一条记录,如何查询SQL Server数据库中的下一条记录? [英] How to Query Next Record in SQL server Database if we had selected the previous single record?

查看:125
本文介绍了如果我们选择了上一条记录,如何查询SQL Server数据库中的下一条记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一次从SQL Server中选择一条记录. &想要在C#或ASP.net中选择按钮的单击事件上的下一个/上一个记录.




我想使用ASP.net中的图片库的上一个和下一个按钮.

I want to select a single record at a time from SQL Server. & want to select next/previous record on button''s click event in C# OR ASP.net.


OR

I wanna use next & previous button for the photo gallery in ASP.net

推荐答案

您的查询将与此类似,只需设置偏移量即可.

your query will be somewhat similar like this, just set the offset.

SELECT * FROM (
	SELECT TOP 1 * FROM (
		SELECT TOP [Y] LogID,EventID,Priority,Severity,Title
		FROM [LOG]
		WHERE Severity='Error'
		ORDER BY LogID  ASC) as InnerTable
	ORDER by LogID DESC) as OuterTable
ORDER by LogID ASC

-- Replace [Y] with the offset.


我不明白你要做什么.
让我知道我是否对你正确?
我猜您的查询返回了多行.现在,在您的UI中,您需要一次显示1条记录,然后单击按钮就需要显示下一条记录(在ASP.NET中).如果这是您的要求,则需要使用 DetailsView [ DetailsView分页 [
I don''t understand what you are trying to do.
Let me know if I am getting you right?
I guess your query returns multiple rows. Now in your UI you need to display 1 record at a time and on button click you need to show the next record (in ASP.NET). If this is you requirement, you need to use a DetailsView[^].
You can loop through the next record using DetailsView Paging[^].

If this is not what you want, give an explanation of your requirement.


好,如果您正在谈论从应用程序端读取记录,则可以使用选择查询并获取数据到应用程序层并进行导航,但是,如果您尝试在sql服务器上进行操作,则会有些困难(但希望可以通过传递参数来实现),一旦您从中读取数据,就回到应用程序层数据库,您可以使用数据集或集合来存储它.这将允许您根据需要进行导航,但是,如果使用datareader,则将仅允许您进行导航,而不能向后导航...
ok , if you are talking about reading records from the application end you can just use a select query and get the data to the application layer and navigate through it , but if you are trying to do it at the sql server then it will be bit difficult (but hope it is possible by passing an argument), and back to application layer once you read the data from the DB you can use either dataset or a collection to store it.this will allow you to navigate as you want , but if you use datareader it will allow you to navigate only forward and not backward...


这篇关于如果我们选择了上一条记录,如何查询SQL Server数据库中的下一条记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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