What is ADO? - Creating Objects in JScript, Visual C and .NET
(Page 12 of 12 )
JScript
JScript has a syntax different from VBScript’s, although much of the object usage is similar. The major thing to watch for is that JScript is case-sensitive. For example, to create a recordset in Jscript, you would use:
var objRs = Server.CreateObject("ADODB.Recordset");
Use of the methods and properties is also very similar:
objRs.CursorLocation = adUseClient;
objRs.Open ("authors", objConn, adOpenStatic, _
adLockBatchOptimistic, adCmdTable);
To loop through a recordset in Jscript, you would use:
while (!objRs.EOF)
{
Response.Write (objRs(" field _ name"));
objRs.MoveNext();
}
Visual C++
To use ADO within C++, you must import the ADO library:
#import "c:\program files\common files\system\ado\
msado15.dll" \
no_namespace \
rename( "EOF", "adoEOF" )
You must make sure the file path points to the location of your version of the ADO DLL. The no_namespace keyword is added so that you don’t have to scope the ADO names. The EOF property must be renamed because of an unfortunate name collision with the EOF constant defined in the Standard C library.
Object creation follows this syntax:
_ConnectionPtr pConnection;
pConnection.CreateInstance( __uuidof( Connection ) );
_RecordsetPtr pRecordSet;
pRecordSet.CreateInstance( __uuidof( Recordset ) );
.NET
Although .NET comes with a new data access strategy (ADO.NET), You still can use ADO within .NET if required. For this you must create a .NET wrapper to use the ADO COM components. In Visual Studio .NET you can do this simply by creating a reference to the ADO component; otherwise, you can use the tlbimp.exe tool supplied with .NET to create the wrapper. See the .NET documentation for more details. Once the wrapper is created, ADO use is exactly the same as non-.NET languages.
Summary So far you’ve explored the principles of data access and the range of problems created by the increasing variety and location of data and users. You’ve seen a bird’s eye view of the significance of ADO and its advantages, and briefly looked at the other data access technologies it builds on, replaces, or complements. In particular, you’ve considered:
- Data and data stores
- The existing technologies for accessing data, and Microsoft’s scheme to streamline data access, UDA
- What OLE DB and ADO are, and how they tie in with each other
- The distinction between data providers and data consumers, and Microsoft’s Distributed interNet Application Architecture framework for client/server solutions
- The new features of ADO 2.5 and 2.6
- The security changes introduced in ADO 2.8
- How to use the basics of ADO in a variety of languages
The next chapter discusses the ADO and ADOX object models.
This is from ADO Programmer's Reference, by Dave Sussman (Apress, ISBN 1590593421). Check it out at your favorite bookstore today. Buy this book now. |
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |