Visual Basic 6 Black Book:Working With Database Objects In Code
function GetCookie (name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg) {
var end = document.cookie.indexOf (";", j);
if (end == -1)
end = document.cookie.length;
return unescape(document.cookie.substring(j, end));
}
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
var m1='';
var gifstr=GetCookie("UsrType");
if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; }
document.write(m1+m2+m3);
Keyword
Title
Author
ISBN
Publisher
Imprint
Brief
Full
Advanced Search
Search Tips
Please Select
-----------
Components
Content Mgt
Certification
Databases
Enterprise Mgt
Fun/Games
Groupware
Hardware
IBM Redbooks
Intranet Dev
Middleware
Multimedia
Networks
OS
Prod Apps
Programming
Security
UI
Web Services
Webmaster
Y2K
-----------
New Titles
-----------
Free Archive
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98
function isIE4()
{
return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') );
}
function bookMarkit()
{
var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0";
parent.location.href=url;
//var win = window.open(url,"myitk");
//if(!isIE4())
// win.focus();
}
Search this book:
Previous
Table of Contents
Next
DAO: Creating A Record Set
After youve finished defining a database table with a DAO TableDef object, you can append that object to a Database object, which adds that table to that database. After youve installed the new table, you can use the OpenRecordset method to open a record set and start working with data:
Set recordset = Database.OpenRecordset (source, type, options, lockedits)
Here are the arguments for OpenRecordset:
sourceA string specifying the source of the records for the new Recordset object. The source can be a table name, a query name, or an SQL statement that returns records. (For table-type Recordset objects in Jet-type databases, the source can only be a table name.)
typeIndicates the type of Recordset to open.
optionsCombination of constants that specify characteristics of the new Recordset.
lockeditsConstant that determines the locking for Recordset.
Here are the possible settings for type:
dbOpenTableOpens a table-type Recordset object.
dbOpenDynamicOpens a dynamic-type Recordset object, which is like an ODBC dynamic cursor.
dbOpenDynasetOpens a dynaset-type Recordset object, which is like an ODBC keyset cursor.
dbOpenSnapshotOpens a snapshot-type Recordset object, which is like an ODBC static cursor.
dbOpenForwardOnlyOpens a forward-only-type Recordset object (where you can only use MoveNext to move through the database).
Here are the possible settings for options:
dbAppendOnlyAllows users to append new records to the Recordset but prevents them from editing or deleting existing records (Microsoft Jet dynaset-type Recordset only).
dbSQLPassThroughPasses an SQL statement to a Microsoft Jet-connected ODBC data source for processing (Jet snapshot-type Recordset only).
dbSeeChangesGenerates a runtime error if one user is changing data that another user is editing (Jet dynaset-type Recordset only).
dbDenyWritePrevents other users from modifying or adding records (Jet Recordset objects only).
dbDenyReadPrevents other users from reading data in a table (Jet table-type Recordset only).
dbForwardOnlyCreates a forward-only Recordset (Jet snapshot-type Recordset only). It is provided only for backward compatibility, and you should use the dbOpenForwardOnly constant in the type argument instead of using this option.
dbReadOnlyPrevents users from making changes to the Recordset (Microsoft Jet only). The dbReadOnly constant in the lockedits argument replaces this option, which is provided only for backward compatibility.
dbRunAsyncRuns an asynchronous query (ODBCDirect workspaces only).
dbExecDirectRuns a query by skipping SQLPrepare and directly calling SQLExecDirect (ODBCDirect workspaces only).
dbInconsistentAllows inconsistent updates (Microsoft Jet dynaset-type and snapshot-type Recordset objects only).
dbConsistentAllows only consistent updates (Microsoft Jet dynaset-type and snapshot-type Recordset objects only).
Here are the possible settings for the lockedits argument:
dbReadOnlyPrevents users from making changes to the Recordset (default for ODBCDirect workspaces).
dbPessimisticUses pessimistic locking to determine how changes are made to the Recordset in a multiuser environment.
dbOptimisticUses optimistic locking to determine how changes are made to the Recordset in a multiuser environment.
dbOptimisticValueUses optimistic concurrency based on row values (ODBCDirect workspaces only).
dbOptimisticBatchEnables batch optimistic updating (ODBCDirect workspaces only).
Lets see an example to make this clearer. In the previous few topics, weve developed a TableDef object, td, in our DAO code example, the daocode project. To append that object to the Database object we created, db, we use the Append method of the database objects TableDefs collection. After installing the table, we open it for use with the Database objects OpenRecordset method this way, creating a new DAO Recordset, which we name dbrecordset:
Sub CreateTable()
Set td = db.CreateTableDef(TableForm.Text1.Text)
Set fields(0) = td.CreateField(TableForm.Text2.Text, dbText)
Set fields(1) = td.CreateField(TableForm.Text3.Text, dbText)
td.fields.Append fields(0)
td.fields.Append fields(1)
Set dbindex = td.CreateIndex(TableForm.Text2.Text + "index")
Set IxFlds = dbindex.CreateField(TableForm.Text2.Text)
dbindex.fields.Append IxFlds
td.Indexes.Append dbindex
db.TableDefs.Append td
Set dbrecordset = db.OpenRecordset(TableForm.Text1.Text, dbOpenTable)
End Sub
In this case, were opening the new record set as a standard DAO table by passing the constant dbOpenTable. We also declare dbrecordset as a form-wide variable:
Dim dbrecordset As Recordset
At this point in the daocode project, then, weve created a new database with a table in it that has two fields, using the names that the user supplied for the fields and the table itself. And weve opened that table as a record set, so were ready to work with it and add data to it, which well do in later topics in this chapter.
Besides creating a new database as weve done, however, the user may want to open an existing database, and well see how to do that in the next topic.
Previous
Table of Contents
Next
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.
Wyszukiwarka
Podobne podstrony:
863 03863 ind863 (2)863 06863 08859 863863 12863 07863 05863 00865 Historia doktryn politycznych863 11Meta 865(1)863 14więcej podobnych podstron