|
|
|
The Example Code
Throughout the book, you will find references to
example
code and utilities. All of this code can be found here on the CD. Feel free to grab any
code snippet that you find useful and play
with it, break it, put it in your application, etc. However, all code
is provided on an "as-is" basis. This means it's not guaranteed in any way. See
the license agreement that comes with the book. Here are a few tips to
help you get started:
- You'll probably want to copy the
contents of the CD to a local hard disk--not a shared directory
on another system. While this might work for the Visual Basic 6.0
examples, the .NET examples won't be "trusted" if they are not loaded
from a local hard disk or other R/W media.
- The VB6 examples using DataEnvironment objects
against Access (Jet)
databases assume the databases can be found in the C:\ADO\Databases folder; if you have installed your examples in another location you will need to
modify this prior to running.
- For any of the ODBC examples, you will also need to create the LocalServer
DSN. This DSN simply references the local (.) version of SQL Server.
- Some examples use resources not
available in the CD; these are intended to showcase VB code rather than
to "work out of the box."
- You'll find literally hundreds of
examples on the CD. Yes, some are not mentioned in the book. These were
used to work through issues or simply as a means to create test data.
See the "\Examples\Additional Examples" folder on the CD.
See Setup Instructions for
more detailed information about setting up the databases used by the
examples.
Chapter Referenced Example Code
In most chapters, examples will be
provided to demonstrate the topic being discussed. These examples are
referenced in the text by a footnote such as "Located in the
"\Examples\Chapter06\AddNew" folder on the CD."
To use these
examples, simply use the Visual Studio IDE to load it from that folder.
For VB6 examples up through Chapter
12, load the ".vbp" (project) file or ".vbg" (group) file if one is
present using the Visual Basic IDE. To load the .NET examples, from Chapter
13 and beyond, load the ".sln" (solution) file using the Visual Studio
.NET IDE.
Tip: If you encounter "protection"
errors loading a project, remember that Visual Studio .NET requires
that the files be loaded from a local hard disk--not from a shared
network drive.
Visual Basic 6 Archive Example Code
The CD also includes a number of VB6 examples and tools not specifically
mentioned in the text. Shown below is an outline of the examples, tools
and code snippets you'll find in the VB6 Archive folder on the CD.
| Command Objects |
|
Basic Example: This sample shows how to create a
Command object, make a parameterized SELECT statement, and shows how to
use the "command as method" technique. |
|
Concatenated
Parameters: This sample shows how to take two pieces of data
from text boxes and concatenate them into a SQL string. |
|
Construct
All Types locks providers table:
This utility verifies various cursor abilities that may be supported
by the provider. To use this sample make sure you have the Access
databases and LocalServer DSN installed. This sample also uses a
DataEnvironment object. The output is placed in a file named compare.txt. |
|
Execute
Method: This sample shows
how to append the parameters to a Command object to execute a SQL
string, and later assign their values from data in a Variant array.
It also shows the error that is raised if no parameters are
given. |
|
Profiling
a Command: Compares
executing a parameterized SQL string against OleDb and ODBC. |
|
State:
Shows how to check the state of an executing asynchronous command. |
|
Using
Execution-time options:
This sample forces an error to show how not to set
execution-time options. |
|
Using the
Prepared Property: Shows
how to use the Prepared property of the Command object. Note: The
sample by default uses Prepared=False. |
| |
| Compute
By |
|
Shows how to
call a stored procedure which uses the COMPUTE BY statement. |
| |
| Connecting |
|
The "Connection Pooling ODBC Class"
folder contains code that will enable connection pooling in your
desktop application (you do not need your code if you open your
connections in ASP pages or MTS components). |
| |
| Controls |
|
This folder
contains the handy LabeledTextBox control. |
| Dump All DataTypes |
|
This sample
maps ADO datatype constants to the constant names--useful for code
wizards and error messages. |
| |
| Getting Connected |
|
Async Operations:
Shows how to establish a connection and execute a command asynchronously. |
|
Data Environment with Parm Query:
Shows how to execute a command in a Data Environment which takes a
parameter. |
| |
| Hierarchy and Shape |
|
These
samples show the many combinations of creating and using
hierarchical recordsets with the SHAPE syntax, using SQL statements,
stored procedures, with different parameter styles, etc. |
| |
| ODBC API |
|
Here you
will find miscellaneous code samples for not only the ODBC API but
ADO, Jet, XML, and other technologies. |
| |
| Passing Data between Layers |
|
This set of
samples tackle the same problem--passing data between layers--with
different strategies, such as using Recordsets, Variant Arrays,
Strings, Property Bags, etc. |
| |
| Print and Raiserror |
|
Shows the
use of RAISERROR and PRINT SQL statements, and the usage of the
InfoMessage event. |
| |
| Record and Stream |
|
These
samples show the use of the ADODB.Record object and how to open a
resource by URL. |
| |
| Recordset Objects |
|
The
miscellaneous samples in this folder show how to open recordsets,
how to do asynchronous retrievals of information, how to use the
Sort, Filter, and Find methods, how to manage multiple resultsets
from stored procedures, etc. |
| |
| Stored Procedure Add-In for VB |
|
This Add-In
generates the code necessary to call a stored procedure, looking it
up in the database and creating all the logic required to append the
parameters. |
| |
| Stream Examples |
|
All the
stream examples show the use of the ADODB.Stream object, plus other
miscellaneous examples on the use of timestamps, UpdateBatch, etc. |
| |
| Tips and Techniques |
|
Here you
will find code snippets to
- Shuffle ("Encrypt") strings
- Pass multiple recordsets across layers
- Reference SQL 7.0 Linked Servers
- Grant all permissions to all users |
|