863 865




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 you’ve 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 you’ve 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:

•  source—A 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.)
•  type—Indicates the type of Recordset to open.
•  options—Combination of constants that specify characteristics of the new Recordset.
•  lockedits—Constant that determines the locking for Recordset.

Here are the possible settings for type:

•  dbOpenTable—Opens a table-type Recordset object.
•  dbOpenDynamic—Opens a dynamic-type Recordset object, which is like an ODBC dynamic cursor.
•  dbOpenDynaset—Opens a dynaset-type Recordset object, which is like an ODBC keyset cursor.
•  dbOpenSnapshot—Opens a snapshot-type Recordset object, which is like an ODBC static cursor.
•  dbOpenForwardOnly—Opens a forward-only-type Recordset object (where you can only use MoveNext to move through the database).

Here are the possible settings for options:

•  dbAppendOnly—Allows users to append new records to the Recordset but prevents them from editing or deleting existing records (Microsoft Jet dynaset-type Recordset only).
•  dbSQLPassThrough—Passes an SQL statement to a Microsoft Jet-connected ODBC data source for processing (Jet snapshot-type Recordset only).
•  dbSeeChanges—Generates a runtime error if one user is changing data that another user is editing (Jet dynaset-type Recordset only).
•  dbDenyWrite—Prevents other users from modifying or adding records (Jet Recordset objects only).
•  dbDenyRead—Prevents other users from reading data in a table (Jet table-type Recordset only).
•  dbForwardOnly—Creates 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.
•  dbReadOnly—Prevents 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.
•  dbRunAsync—Runs an asynchronous query (ODBCDirect workspaces only).
•  dbExecDirect—Runs a query by skipping SQLPrepare and directly calling SQLExecDirect (ODBCDirect workspaces only).
•  dbInconsistent—Allows inconsistent updates (Microsoft Jet dynaset-type and snapshot-type Recordset objects only).
•  dbConsistent—Allows only consistent updates (Microsoft Jet dynaset-type and snapshot-type Recordset objects only).

Here are the possible settings for the lockedits argument:

•  dbReadOnly—Prevents users from making changes to the Recordset (default for ODBCDirect workspaces).
•  dbPessimistic—Uses pessimistic locking to determine how changes are made to the Recordset in a multiuser environment.
•  dbOptimistic—Uses optimistic locking to determine how changes are made to the Recordset in a multiuser environment.
•  dbOptimisticValue—Uses optimistic concurrency based on row values (ODBCDirect workspaces only).
•  dbOptimisticBatch—Enables batch optimistic updating (ODBCDirect workspaces only).

Let’s see an example to make this clearer. In the previous few topics, we’ve 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 object’s TableDefs collection. After installing the table, we open it for use with the Database object’s 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, we’re 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, we’ve 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 we’ve opened that table as a record set, so we’re ready to work with it and add data to it, which we’ll do in later topics in this chapter.

Besides creating a new database as we’ve done, however, the user may want to open an existing database, and we’ll 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 03
863 ind
863 (2)
863 06
863 08
859 863
863 12
863 07
863 05
863 00
865 Historia doktryn politycznych
863 11
Meta 865(1)
863 14

więcej podobnych podstron