display particular set of records

Posted by Kannan1986 under Sql Server on 1/20/2010 | Views : 1768 | Status : [Member] | Replies : 6
How do display particular set of records from sql 2005 using asp.net ?

For example:

I have a table with 50 records. but i want to display 20th records to 30th records only or 43 rd records to 3rd records......




Responses

Posted by: RtpHarry on: 1/24/2010 [Member] [MVP] Bronze

Up
0
Down
This is why I love linq because its as simple as saying something like:


int PageSize = 25;
var query = db.Orders.Skip(4 * PageSize).Take(PageSize);




Kannan1986, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Abhi2434 on: 1/25/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
But RtpHarry,

I like LINQ anyway (its great) but parsing all the data through linq is not a great technique when you have crores of data.

LINQ actually internally create a loop...

Anyway, urs is also a solution.
Cheers.

www.abhisheksur.com

Kannan1986, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Abhi2434 on: 1/20/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
Use ROW_NUMBER. Also remember, you have to specify the ordering, on which you want to fetch these records. See how I am writing one query which does the same thing :

SELECT A.* FROM [dbo].[Category] A

INNER JOIN
(SELECT TOP 1000 ROW_NUMBER() OVER(ORDER BY CAT_CD DESC) AS 'RN', CAT_CD
FROM [dbo].[Category]) B ON A.CAT_CD= B.CAT_CD
AND B.RN between 5 and 10

This will give you record from 5 to 10.

Here the Inner table
SELECT TOP 1000 ROW_NUMBER() OVER(ORDER BY CAT_CD DESC) AS 'RN', CAT_CD

FROM [dbo].[Category]

will give you the record with its Row_Number.

Cheers.

www.abhisheksur.com

Kannan1986, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 1/20/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
You can bind the Data to the Gridview and enable paging and in the gridview there is a property that gives you an option to choose how many records you want to display , the property is pagesize

Thank you for posting at Dotnetfunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Kannan1986, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sndsuresh on: 1/21/2010 [Member] Starter

Up
0
Down
You can achive exactly functioanlity using third party control called teliric rad grid control.

Kannan1986, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nishithraj on: 1/22/2010 [Member] Bronze

Up
0
Down
Whatever Abhi said will work out. In addition to that you can refer the following URL to get more info..

http://stackoverflow.com/questions/1902009/getting-the-nth-most-recent-business-date-very-different-query-performance-usin

Mark this as answer, if it is.....

With regards
Nishithraj Narayanan

Kannan1986, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response