Low cost ecommerce web development India flash website design
Recordset objects provide more functionality than simply a method for
holding and scrolling through data. A Recordset object is a table of values. It
has rows and columns like a database table; but a Recordset object is not a
table. It's more like a virtual table or view.
First, the values of the Recordset object's columns may come from several
different tables via a JOIN operation. Second, the column values may be
calculated values — they may not match any value in the database. Finally,
you can search and sort Recordset objects, rum them into strings or arrays,
and even persist them to and retrieve them from disk storage as objects or as
XML data.
Using the Recordset.Open Method
If you need a Recordset object with any type of cursor other than a forwardonly,
read-only cursor, you need to open it directly rather than calling the
Execute method of a Connection object. Recordset objects also have an Open
method, which takes several arguments
Recordset.Open CommandText, Connection|ConnectionString,
Cursor-Type, LockType, Options
The CommandText argument contains the SQL query. The Connection |
ConnectionString argument contains either a reference to an open Connection
object or a valid ConnectionString argument If you use a ConnectionString
argument, the Open method creates a Connection object for you.
If you're going to make only one call to the database in a page, letting
create a Connection object is a viable option. However, if you're going to
make more than one call, you should create and open your own Connection
object. The reason is that you have more control over the type and duration of
the Connection object if you open and close it yourself.
The CursorType argument is a value derived from one or more
adCursorTypeEnum values. The following list shows the valid values and a
description of each:
§ adOpenForwardOnly
Returns a forward-only cursor. This is the default cursor type. If you don't
specify a cursor type,
name implies, you can only move forward, not backward, through the
Recordset object. You should use this whenever you need to make only
one pass through a Recordset object because it's the fastest type of cursor.
§ adOpenKeyset
Returns a keyset cursor. You can move in any direction with this cursor
62
type first, last, forward, backward, skip, or move to bookmark (if the
provider supports bookmarks). You can see changes that others make to
the records in the Recordset object, but you can't see records added since
you opened the Recordset object. You cannot access or change records that
other users delete. Use a keyset cursor for large record sets where you need
to be able to scroll backward or you need to change. The server creates a
unique bookmark for each row when you first run the query. Those
bookmarks don't change during the life of the Recordset object, which is
why you can't see new records.
§ adOpenDynamic
Returns a dynamic cursor. This type is exactly like a keyset cursor except
that you can see new records that others add. A dynamic cursor checks
constantly for updates and additions to the result set. It does not build a set
of bookmarks for the result set, so a dynamic cursor often opens more
quickly than a keyset cursor. Dynamic cursors require the most resources
of all cursor types, so you should not use them unless you need to see
additions to the result set while the Recordset object is open.
§ adOpenStatic
Returns a static cursor, which is a fixed copy of a set of records. You
cannot see any changes or inserts by others without querying the database
again. Recordset objects with static cursors can be updated.
Depending on the provider, you may be able to see changes your application
makes to data with a static cursor.
The LockType argument tells
you want to avoid locking data for updates or inserts because locks created by
one user can cause problems for other users in your application. Read-only
locks do not cause such problems. The valid LockType arguments are:
§ adLockReadOnly
Read-only — you cannot alter the data.
§ adLockPessimistic
Pessimistic locking is the strongest type of lock. Records with pessimistic
locking are unavailable to other users of your application. Pessimistic locks
occur when the server delivers the record. The record remains locked until
you close the Recordset object You should avoid pessimistic locking in
Web applications whenever possible.
§ adLockOptimistic
Optimistic locking locks records just before an update occurs, and unlocks
them immediately afterward. Other users can access data during the time
you're updating the record, which means they may potentially be viewing
outdated data. Similarly, with optimistic locking, multiple users may
63
simultaneously try to update the same data, leading to problems. You
should avoid optimistic locking in Web applications whenever possible.
§ adLockBatchOptimistic
Optimistic batch locks act like optimistic locks, except they work for batch
updates — deferring immediate updates in favor of updating many records
at one time rather than updating each record immediately as with
adLockOptimistic locking. It's your call whether batch updates or
immediate updates are better for your application, in part, it depends on the
level of interactivity your application demands and how people expect to
use the application.
The final Recordset.Open argument is the Options flag. The Options flag
takes exactly the same values as the Connection.Execute options argument.
Again, the options argument is not required, but you should always include it.
It tells
SQL statement.
The Update method fails because even though the Recordset object may have
an updateable cursor type, the underlying connection is read-only. To open an
updateable Recordset object you must set the ConnectionMode property to
adModeReadWrite.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73