Solved

Recordset vs Cursor

Posted on 2003-10-28
14
964 Views
Last Modified: 2008-02-01
What's the difference between a recordset and cursor?
0
Comment
Question by:vbtiger
  • 5
  • 5
  • 3
  • +1
14 Comments
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 9632992
a recordset may be implemented via a cursor
or someother means

a cursor is a Database object which allows the programmer to step throught the result set
and nake processing decisions based on the rows contained within it...

a recordset  is a result set returned to an external (to the database ) program
which the external program provides the capability to navigate...

hth

have you a specific scenario in mind?
0
 
LVL 30

Expert Comment

by:nmcdermaid
ID: 9633009
Generally speaking you would use a cursor to scroll through a recordset.

A recordset usually refers to an entire set of rows, ie the result of a select from a table or from the SQL recordset functions. A recordset may have zero, one, or more rows.

A cursor is the is an object you can use to scroll through a recordset, allowing you to access one row at a time.

These words have slightly different meanings depending on whether you are using SQL-DMO, DTS, VB, T-SQL, etc.

You may wish to narrow your question down a bit.

0
 
LVL 18

Expert Comment

by:ShogunWade
ID: 9633203
Sounds to me like a homework question!
0
 

Author Comment

by:vbtiger
ID: 9633276
Hi all,

Thanks for the quick response.  Actually,  I will be working on a new system based on VB + SQL Server.  I have only experience in developing applications with VB + Access.  I was reading through some articles on cursors and was wondering what the difference between an ADO recordset and cursor is.

BTW,  I need some info to get me started on SQL server.  Any links/pointers would be much appreciated.  I can increase the points if it is really worth it.

Thanks again!
0
 
LVL 18

Assisted Solution

by:ShogunWade
ShogunWade earned 25 total points
ID: 9633344
I retract my comment then.

Basically as mentioned.   The results of a query are a set of records (ie recordset)  if you want to perform itterative operations on a set of records you need a "pointer" into the set. This "pointer" is a cursor and it allows you to navigate through a recordset pointing as a single row at any one time.

There are lots of different types of cursor.   You can for example set up cursors in SQL Server which arent exposed to a client application.  or you can set up a cursor on a client app by doing something like this

dim a as recordset
.....

a.open
...
cursor is not esablished.


a cursor generated on a client app can be client side or server side (this defines who is in charge of managing the pointer position (in a very simplistic sense))


Are you completely new to databases or have u had any SQL experience eg( oracle, sybase, MSAccess (lets pretend its sql), etc.)
0
 
LVL 18

Expert Comment

by:ShogunWade
ID: 9633356
oops prev post meant to say

 cursor is now esablished.

as opposed to

cursor is not esablished.

0
 
LVL 30

Accepted Solution

by:
nmcdermaid earned 25 total points
ID: 9633361
There is no ADO object called a cursor. Your question is a bit vague, what kind of cursor? I have explained generally the difference between a cursor and a recordset.

You can move through a recordset like a T-SQL cursor in ADO, but there is nothing called a cursor.

When you say Cursor possibly you mean the CursorLocation property? client and server cursors have their own advantages and disadvantages, but it is not something you need to worry about at this early stage.


I assume in Access you used the DAO library to access the DB

To use MS SQL through VB you will most likely be using the ADO library, which is slightly different to the DAO version, but recordsets mean the same thing in both libraries (though the objects are a bit different)

Someone else may be able to recommend a book or link to get you started with developing on SQL, but if you firstly check out the ADO help in VB that is a good start.

0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 18

Expert Comment

by:ShogunWade
ID: 9633410
There are cursros in ADO!

Without cursors it is not possible to iterate through a recordset!

Cursors in ADO are implemented "behind the scenes"

when you open an ADO recordset you are implicitly establishing a cursor and on closing it you are destroying the cursor.

The existance of a cursor provides you with the ability to perform calls such as

.MoveFirst
.MoveLast
.MoveNext

etc.
0
 
LVL 30

Expert Comment

by:nmcdermaid
ID: 9633497
Yes of course a cursor is implemented behind the scenes in ADO but as I said there is no ADO object called a cursor.


0
 

Author Comment

by:vbtiger
ID: 9633573
Hi ShogunWade,

I do have experience in developing applications with Access as backend and am also familiar with Oracle to a certain extent (PL/SQL).
0
 
LVL 18

Expert Comment

by:ShogunWade
ID: 9633664
"also familiar with Oracle "

ok SQL Server is pretty sumilar to oracle but there are differences.   for example

in SQL Server you can do:

SELECT 'fred'

which returns a recordset of 1 field with 1 value  'fred'

in oracle

you must do:

SELECT 'fred' FROM DUAL.

There are a numer of other differences but as you will see from above it is prodominently syntactical.    I would suggest scanning through sql books on line (commonly refered to as BOL) there are various simple examples in there as well as documentation.   Also look at the sample database Northwind or Pubs  both illustrate the basics of SQL Server.



0
 

Author Comment

by:vbtiger
ID: 9639209
0
 

Author Comment

by:vbtiger
ID: 9639212
Thanks guys!
0
 

Author Comment

by:vbtiger
ID: 9639231
From the same site:

When your application retrieves rows of data from SQL Server, it needs a place to store the rowset while it processes the information. An ADO Recordset object encapsulates the data and the operations allowed on that data. The Recordset object uses a cursor as a mechanism to organize the temporary storage. The cursor is similar to a dynamic array stored in memory, and the Recordset object is your interface to that array.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now