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
ADO: Opening A Connection
The Testing Department is calling again. The company is switching to using ActiveX Data Objectshow about setting up an ADO database-editing program? Already on it, you say.
The first step in editing an ADO database is to open that database, which is called a data source in ADO terminology, by setting up a Connection object. To use that and other ADO objects in code, you use the Project|References item, select the Microsoft ActiveX Data Objects Library item, and click on OK, adding the ADO Object Library to your program.
Now were free to create a new ADO Connection object with the Connection objects Open method:
connection.Open ConnectionString [,UserID [, Password [, OpenOptions]]]
Here are the arguments for this method:
ConnectionStringString containing connection information.
UserIDString containing a username to use when establishing the connection.
PasswordString containing a password to use when establishing the connection.
OpenOptionsIf set to adConnectAsync, the connection will be opened asynchronously.
Lets see an example. When we start our ADO code example, the adocode example (see A Full-Scale ADO Example in this chapter), well establish a connection, db, to the database we built in the previous chapter, db.mdb:
Private Sub Form_Load()
Dim db As Connection
Set db = New Connection
db.Open "PROVIDER=Microsoft.Jet.OLEDB.3.51;Data _
Source=C:\vbbb\adocode\db.mdb;"
...
End Sub
And thats itnow we have a connection to the data source. To actually work with the data in that data source, well create an ADO record set in the next topic.
ADO: Creating A Record Set From A Connection
Now that youve created an ADO connection, you can open a record set from that connection using the Recordset objects Open method:
recordset.Open [Source, [ActiveConnection, [Type, [LockType, [Options]]]]
Here are the arguments for this method:
SourceA valid Command object variable name, an SQL statement, a table name, a stored procedure call, or the file name of a Recordset.
ActiveConnectionA valid Connection object variable name or a string containing ConnectionString parameters.
TypeSets the Recordset type (see the following list).
LockTypeA value that determines what type of locking (concurrency) the provider should use when opening the Recordset (see the following list).
OptionsA Long value that indicates how the provider should evaluate the Source argument if it represents something other than a Command object, or that the Recordset should be restored from a file where it was previously saved (see the following list).
Here are the possible values for the Type argument:
dbOpenKeysetOpens a dynaset-type Recordset object, which is like an ODBC keyset cursor.
dbOpenDynamicOpens a dynamic-type Recordset object, which lets the application see changes made by other users.
dbOpenStaticOpens a static-type Recordset object.
dbOpenForwardOnlyOpens a forward-only-type Recordset object, where you can only use MoveNext to move.
Here are the possible values for the LockType argument:
adLockReadOnlyThe default; read-only.
adLockPessimisticPessimistic locking, record by record.
adLockOptimisticOptimistic locking, record by record.
adLockBatchOptimisticOptimistic batch updates.
Here are the possible values for the Options argument:
adCmdTextProvider should evaluate Source as a definition of a command.
adCmdTableADO should generate an SQL query to return all rows from the table named in Source.
adCmdTableDirectProvider should return all rows from the table named in Source.
adCmdStoredProcProvider should evaluate Source as a stored procedure.
adCmdUnknownType of command in the Source argument is not known.
adCommandFileRecord set should be restored from the file named in Source.
adExecuteAsyncSource should be executed asynchronously.
adFetchAsyncAfter the initial quantity specified in the CacheSize property is fetched, any remaining rows should be fetched asynchronously.
Lets see an example. In our ADO code example, the adocode example (see A Full- Scale ADO Example in this chapter), we create a record set, adoRecordset, by first declaring it as a form-wide variable:
Dim adoRecordset As Recordset
Next, we select all the records in the students table this way when the form loads, using the Open method:
Private Sub Form_Load()
Dim db As Connection
Set db = New Connection
db.Open "PROVIDER=Microsoft.Jet.OLEDB.3.51;Data _
Source=C:\vbbb\adocode\db.mdb;"
Set adoRecordset = New Recordset
adoRecordset.Open "select Grade, Name from students", _
db, adOpenStatic, adLockOptimistic
...
End Sub
Now that weve opened our result set, we can bind that result set to various controls, like text boxes, as well do 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:
887 (2)884 886ReadMe (884)879 884887 890882 884avt 887 Programator sterowany z pakietu BASCOMwięcej podobnych podstron