Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / May 2005

Tip: Looking for answers? Try searching our database.

Using a cursor SQL server side Problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jon W - 27 May 2005 00:28 GMT
Hello All
Thank you for any help you can provide!

I have a long list of links with decscriptions titles etc in a SQL Server
2000 database. The basic problem is that I am attempting to use a data base
cursor to to the proper starting point in a sorted view, get the next 10-or
20 records and return them. Problem is ony one record is being returned.

Here is the code
SQL
ALTER PROCEDURE dbo.PS_GetLinks
@start as int, @rcount as int
AS
declare @ACounter as tinyint
declare @RecordCount as tinyint
set @ACounter=1
set @RecordCount = (Select Count (id) FROM Selectlinks)

Declare My_Cursor CURSOR SCROLL for SELECT URL, Title, description,
@RecordCount as Rcnt
FROM Selectlinks

Open My_Cursor
Fetch absolute @start FROm My_Cursor

WHILE (@ACounter < @rcount)
   BEGIN

       fetch next FROM My_Cursor

       set @ACounter = @ACounter + 1

   END

Close My_Cusor

Deallocate my_Cursor

RETURN

--ASP NET code below

Dim Start As Int64 = 1 '(mPage * (10 - 9))

Dim rd As SqlClient.SqlDataReader

Dim cmd As SqlClient.SqlCommand = con.CreateCommand

Dim lnk As HyperLink

Try

cmd.Parameters.Add("@start", 1)

cmd.Parameters.Add("@rcount", 10)

cmd.CommandText = "PS_GetLinks"

cmd.CommandType = CommandType.StoredProcedure

con.Open()

rd = cmd.ExecuteReader

While rd.Read

lnk = New HyperLink

lnk.NavigateUrl = rd("URL").ToString

lnk.Text = rd("title")

centercontent.Controls.Add(lnk)

centercontent.Controls.Add(New LiteralControl("<br>"))

'RecordCount = rd("rcnt")

End While

Dim nav As New MultiPage(mPage, 10, 340)

centercontent.Controls.AddAt(0, nav.buildnav)

'Catch ex As Exception

Finally

If Not rd Is Nothing Then

rd.Close()

End If

If Not con Is Nothing Then

con.Close()

End If

End Try
Mary Chipman [MSFT] - 30 May 2005 17:38 GMT
So why are you using a cursor instead of a SELECT statement with a
WHERE clause?

--Mary

>Hello All
>Thank you for any help you can provide!
[quoted text clipped - 97 lines]
>
>End Try

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.