**************************************************************** MICROSOFT SQL WORKSTATION 6.0 DB-LIBRARY FOR VISUAL BASIC SAMPLE PROGRAMS **************************************************************** This file tells about the DB-Library for Visual Basic sample programs included with Microsoft(R) SQL Workstation 6.0. The information in this file supplements the information in your Microsoft SQL Workstation documentation. **************************************************************** DB-LIBRARY FOR VISUAL BASIC SAMPLE APPLICATIONS DB-Library for Visual Basic provides a set of sample applications that demonstrate the use of many DB-Library for Visual Basic functions and routines. You can use the code in these sample applications as models or templates for your own applications. By cutting and pasting code from specific application files, by using global procedures from the sample common code files, and by including the declarations for those procedures from the sample include files, you can quickly create the foundation for your own applications. The QUERY sample application demonstrates the following SQL Server operations. Each sample: * Logs in and opens a connection to SQL Server from the client. * Allows a user to choose which database to use. * Allows the user to send a query to SQL Server. * Accepts results from SQL Server and returns the results to the user. * Closes the SQL Server connection. * Exits the application. * Handles any errors or messages generated by these operations. The rest of this file describes the contents of all of the Project files used by the QUERY sample application. This information is organized by the names of the subdirectories in which each Project file resides. Once you are familiar with the QUERY sample applications and their use of the common code directories, refer to the other sample applications provided for examples of implementing additional SQL Server features. COMMON CODE The files in the subdirectory DBLIB\VSAMPLES\COMMON contain general code that can be used by all DB-Library for Visual Basic applications. The QUERY sample application include all of the COMMON files with their Project files and invoke the procedures that these files contain. The following sections describe the files contained in the COMMON subdirectory. The VBSQLGEN.BAS File The VBSQLGEN.BAS module defines a set of procedures that perform tasks common to most DB-Library for Visual Basic applications. Such tasks include: * Opening and closing a SQL Server connection * Processing SQL queries * Executing SQL commands * Displaying error messages The LOGIN.FRM File The LOGIN.FRM file calls a subroutine in the VBSQLGEN.BAS module that uses DB-Library for Visual Basic functions to open a SQL Server connection and log in users. The code for logging in users is used in all of the sample applications except the browse-mode example. The CHNGDB.FRM File The CHNGDB.FRM file uses the DB-Library for Visual Basic function SqlUse% to change the current database to a database name supplied by the user. The code for changing databases is used in all of the sample applications. THE WINCODE DIRECTORY The files in the DBLIB\VSAMPLES\WINCODE subdirectory contain code that is available for use by all applications. To use the common code, you can add the files to a Visual Basic Project or you can copy the code from these files into an existing file. The following sections describe the files in the WINCODE subdirectory. INIEXITW.BAS INIEXITW.BAS contains DB-Library initialization and exit code. RESULTSW.BAS RESULTSW.BAS contains procedures for handling compute rows and stored procedure output parameters. These procedures are called by the Process_Sql_query procedure defined in VBSQLGEN.BAS. THE VBQUERY DIRECTORY The directory DBLIB\VSAMPLES\QUERY include the project make file for the sample application and the sample application's primary, or startup, form, VBQUERY.FRM. VBQUERY.BAS and VBSQL.BAS VBQUERY.BAS and VBSQL.BAS contain the global definitions for this application. They include the relevant variable definitions from GENGLOB.BAS. These are required. The VBSQL.BAS file contains the global definitions for VBSQL functions and constants. ADDITIONAL SAMPLE APPLICATIONS This section provides information about some of the other DB-Library for Visual Basic sample applications provided in your package. The TEXT Sample Application The TEXT sample application enables users to select text files from a database, and view and edit the text in the text file. The TEXT.FRM file of the TEXT project contains the code of the main form of the application. It includes subroutines for selecting, retrieving, and editing text files. For example, the LoadText subroutine contains DB-Library for Visual Basic functions that read text fields from database tables; the InsertText subroutine contains DB-Library for Visual Basic functions that insert text into database text tables. The IMAGE Sample Application The IMAGE sample application enables users to select image files from a database, view images, and add images to a database. It looks and works much like the preceding TEXT sample application. The IMAGE.FRM file of the IMAGE project contains the code of the main form of the application. It includes subroutines for selecting, retrieving, and adding image files. For example, the LoadImage subroutine contains DB-Library functions that read images from databases; the InsertImage subroutine contains DB-Library functions that insert images into databases. The BROWSE Sample Application The BROWSE sample application demonstrates the use of DB-Library for Visual Basic browse-mode functions. The BROWSE project uses the common code files VBSQLGEN.BAS and ABOUT.FRM. The code from the GENGLOB.BAS file is included in the BROWSE.BAS global file. The BLOGIN.FRM file includes the code from the common code file LOGIN.FRM. However, because the browse mode requires two SQL Server connections, the code to open a connection is repeated. The OK_BUTTON_Click subroutine of the BLOGIN.FRM file illustrates the correct way to open SQL Server connections for browsing. The BROWSE.FRM file of the BROWSE project contains the code of the main form of the application. It includes subroutines for selecting, retrieving, and updating rows of information. For example, the Select_Button_Click subroutine sends a command to query SQL Server and processes the results of the query; the Update_Button_Click subroutine sends a command to update or change information in results rows; the ProcessResultRow subroutine processes the data in a results row. This subroutine is used in the Select_Button_Click subroutine mentioned previously. The CURSORS Sample Application The CURSORS sample application illustrates the use of cursors in DB-Library for Visual Basic applications. The CURSORS project uses the common code files VBSQLGEN.BAS, and LOGIN.FRM. The code from the GENGLOB.BAS file is included in the CURSORS.BAS global file. The CURSORS.FRM file of the CURSORS project contains the code of the main form of the application. It includes subroutines for opening and closing cursors, fetching rows of data, updating rows, and displaying rows. The RPC Sample Application The RPC sample application shows the use of SqlRpcSend% and related calls. This sample invokes stored procedures directly (not through a language command) and retrieves return status and output parameters. Direct invocation of stored procedures is especially useful with Open Data Services applications. The sample also shows the use of SqlServerEnum% for listing available servers. The RPC sample application contains most of the stored procedure calls in the RPC.FRM module. The RPCLOGIN.FRM file shows the use of SqlServerEnum%. RPC return status and output parameter handling are covered in RESULTSW.BAS, called by the Process_Sql_query function in VBSQLGEN.BAS. The PUBS Sample Application The PUBS sample application is a full-featured application showing how many VBSQL functions can be combined into a business application. This sample shows a data entry and query form for the authors in the pubs database. It illustrates the use of a list box for maintaining a key set of records, browse mode for optimistic concurrency, and building SQL statements based on data entered. It also shows techniques for using Visual Basic features such as MDI child windows and grid controls within an application.