Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Moving to record X in ASP.NET

Posted on 2011-10-19
7
Medium Priority
?
152 Views
Last Modified: 2012-06-21
Hello all!

I remember with standard ASP I used to move the record pointer as follow:

rs.move (20)

or something like that...

How do I do this with ASP.NET?

Thank.
0
Comment
Question by:pvg1975
  • 4
  • 2
7 Comments
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 36994781
In ASP.Net, if you binding dataset, you can loop through dataset values.
Like - http://forums.asp.net/t/1323999.aspx/1

Using this logic you can move to 20th record in dataset.

Raj
0
 

Author Comment

by:pvg1975
ID: 36994881
I dont understand your sample Raj,

This is how Im accesing the table.  

Dim conString = ConfigurationManager.ConnectionStrings("MyDataBase").ConnectionString
Dim con As New SqlConnection(conString)
Dim strQuery As String = "SELECT ................................."
con.Open()
Dim cmd As New SqlCommand(strQuery, con)
Dim RS As SqlDataReader = cmd.ExecuteReader
if rs.read() then
   .....
end if

I need to move to a specific record to paginate a list of thousands of records. For example, if show 20 records per page, and if the user clicks on PAGE 5 I know I have to move the pointer to (5x20)+1 (record 101) and show only the next 20.

I dont want to loop and unnecesary go thru 100 records till I reach record 101. This is fine for just 100 records, but I need to list thousands of them.

I remember I did this with MOVE in ASP, but I dont know how to do it in .NET
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 36994966
Now I understand your question right. This question is already answered.
Please check this question - http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_22941122.html#a20221968

Raj
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:pvg1975
ID: 36995419
Hi again Raj,

Thanks for the comment, I checked out the question and the link (http://msdn.microsoft.com/en-us/library/bh8kx08z(VS.71).aspx) but I still couldnt figure out how to move the pointer straight to an X number of records.

0
 
LVL 20

Expert Comment

by:ddayx10
ID: 36996016
The problem unfortunately is the use of a datareader. I have no problem with datareaders (I like them alot actually) but it is their nature to read only one line of the results at a time in sequence. For some reason there are no methods added to the datareader to advance multiple records forward or backward (it would have been a good thing to do).

So you are forced to re-examine how you want to deal with this:

1. store your data return in an in memory construct such as a dataset and then you should be able to reach in and grab any records you would like at will. The downside of this is it is potentially more resource intensive than a datareader.

2. Probably the more conventionally "professional" approach would be to continue to use a datareader or even a dataset but limit and choose the records you want through your sql statement. This would give you a more streamlined paging mechanism.

NOTE: Depending on what you are paging through a simplistic approach can be had using a sql dataadapter. This often gives you the option to page automatically, cache if you want, and or use ajax to minimize individual data reads.

I don't suppose this is the kind of answer you want. Its certainly not as easy as "just use this method and your done", but I believe it is a good example of the type of options you will have to consider to get this functioning the way you want (unless you are going to loop forward). Loading all that data from sql each time with a datareader with or without a method sounds like it would be kindof "heavy lifting" in your application anyway.

Good Luck
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 36997832
@pvg1975:
ddayx10 clearly explained everything, I believe, there is no further explanation on this. I suggest you to use paging in SQL as ddayx10 mentioned. That would be more efficient, since it loads only required data and would be 'light-weight'

If you want to proceed with this way, let me know - I will provide you an example.

Raj

0
 
LVL 23

Accepted Solution

by:
Rajkumar Gs earned 2000 total points
ID: 36997927
>> 2. Probably the more conventionally "professional" approach would be to continue to use a datareader or even a dataset but limit and choose the records you want through your sql statement. This would give you a more streamlined paging mechanism. <<

This is an sample query that fetch ONLY those records based on 'from' record position and 'to' record position that we mention.
declare @from_position int, @to_position int
set @from_position = 100000
set @to_position = 100100

select * from
(
select *, row_number() over(order by temp_po_id) Serial from tblTesting               
) a 
where Serial between @from_position and @to_position

Open in new window


When you try to 'MOVE TO' some record, give proper from and to record position.

Raj
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question