Tuesday, February 14, 2012

can I read some rows from the middle of rows in DataReader?

helo..
I have 100,000 rows in the database and I want to read results for eg: from 5000 to 5050 by DataReader.
I wrote this code to do this but its too slow:

Dim SlctStr As String = "select * from topicstbl where partID like '" & PagePartID & "'"

Dim ReadCom As New SqlClient.SqlCommand

ReadCom.CommandText = SlctStr

ReadCom.Connection = MainLib.MyConnection

Dim MyReader As SqlClient.SqlDataReader = ReadCom.ExecuteReader()

Dim StartTNum As Long = 5000

For IR As Long = 0 To StartTNum - 1

MyReader.Read()

Next

Do While MyReader.Read

StartTNum += 1

If StartTNum > 5500 Then Exit Do

'''''''''''''''''''

Loop

MyReader.Close()

is there another way to do the same thing better off than this code?

If you are using SQL 2005, use Row_Number() to create rownumbering, and then in your query, add the WHERE clause:

WHERE MyRowNumber BETWEEN 5000 AND 5050

|||thank you..

No comments:

Post a Comment