SQLBase 9.0 Tutorial Guide

210
Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com SQLBase 9.0 Tutorial Guide Created by Suren Behari Product Manager Gupta Technologies

Transcript of SQLBase 9.0 Tutorial Guide

Page 1: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

SQLBase 9.0 Tutorial Guide

Created by Suren Behari

Product Manager

Gupta Technologies

Page 2: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Table of Contents Introduction ............................................................................................................4 System Requirements ...............................................................................................4 Connectivity Architectures .........................................................................................4

ODBC................................................................................................... 4 DAO..................................................................................................... 5 RDO..................................................................................................... 6 OLE DB ................................................................................................ 7 ADO..................................................................................................... 8 Understanding the differences between ADO and ADO.NET .......................... 8 How is ADO.NET different from ADO?........................................................ 8

SQLBase ODBC driver ............................................................................................. 11 System requirements ............................................................................11 ODBC Conformance Level ......................................................................11 Number of Connections and Statements Supported....................................11 Isolation and Lock Levels Supported ........................................................11 Configuring Data Sources.......................................................................11 Data Source Properties dialog .................................................................12 Connection strings ................................................................................13 Connection string keywords....................................................................13 Logon dialog ........................................................................................14

SQLBase OLE DB Data Provider ................................................................................ 15 Overview .............................................................................................15 OLE DB components..............................................................................15 Recommended reading ..........................................................................15 About SQLBase OLE DB Data Provider......................................................15 SQLBase OLE DB Data Provider name ......................................................16 Data source name.................................................................................17 Supported programming tools ................................................................17 Installing .............................................................................................17

Using ADO............................................................................................................. 18 ADO Overview......................................................................................18 ADO features .......................................................................................18 Remote Data Service.............................................................................18 Programming with ADO .........................................................................19 Threading ............................................................................................20 ADO Objects ........................................................................................20 Dynamic Properties Collections ...............................................................20 Working with Data ................................................................................21 SQLBase provider-specific dynamic properties...........................................21 Sample applications ..............................................................................22 Connecting to data through the Provider ..................................................22

.NET Data Provider ................................................................................................. 23 SQLBase .NET implementation................................................................23

Page 3: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Connection pooling in the Connect method ...............................................23 SQLBaseCommand object ......................................................................23 SQLBaseDataReader object ....................................................................24 SQLBaseDataAdapter object ...................................................................24

Tutorials ............................................................................................................... 25 Getting Started................................................................................................. 25

Visual Basic v6.0 Tutorials ....................................................................................... 25 Tutorial 1 ......................................................................................................... 25 Tutorial 2 ......................................................................................................... 39 Tutorial 3 ......................................................................................................... 43 Tutorial 4 ......................................................................................................... 55 Tutorial 5 ......................................................................................................... 63

Visual Basic .NET Tutorials....................................................................................... 71 Tutorial 1 ......................................................................................................... 71 Tutorial 2 ......................................................................................................... 78 Tutorial 3 ......................................................................................................... 84 Tutorial 4 ......................................................................................................... 92 Tutorial 5 ......................................................................................................... 99

C# Tutorials ........................................................................................................ 108 Tutorial 1 ....................................................................................................... 108 Tutorial 2 ....................................................................................................... 117 Tutorial 3 ....................................................................................................... 123 Tutorial 4 ....................................................................................................... 132 Tutorial 5 ....................................................................................................... 145

J# Tutorials ......................................................................................................... 152 Tutorial 1 ....................................................................................................... 152 Tutorial 2 ....................................................................................................... 163 Tutorial 3 ....................................................................................................... 169 Tutorial 4 ....................................................................................................... 179 Tutorial 5 ....................................................................................................... 191

ASP .NET Tutorials................................................................................................ 199 Tutorial 1 ....................................................................................................... 199 Tutorial 2 ....................................................................................................... 203

Page 4: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Introduction The purpose of this guide is to help you install Gupta SQLBase 9.0 on your Workstation and to get you started building applications using Visual Basic 6.0, VB.NET, C#, J# and ASP.NET. The SQLBase 9.0 Tutorial Guide is for first-time SQLBase users, looking to try the new features of Gupta SQLBase 9.0, or for those evaluating SQLBase for use within their organization. This document helps you become familiar with ADO and ADO.NET programming.

System Requirements

Before proceeding through this Tutorial Guide, you should have the following software installed:

♦ SQLBase 9.0

♦ Visual Basic 6.0 & SP5

♦ Visual Studio .NET 2003

♦ Microsoft IIS

♦ Internet Explorer 5 or above

Connectivity Architectures

ODBC

Open Database Connectivity (ODBC) is the first data access technology that provided a common standard interface through SQL for accessing heterogeneous relational databases. With ODBC, an application can access various databases through a single set of common code. The developer just needs to add ODBC drivers to connect the application to the user's choice of data. Today ODBC is available across more than a dozen platforms and a multitude of databases. The general architecture is shown in Figure 1:

Page 5: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Figure 1 - ODBC Architecture

DAO ODBC is more tuned towards the C/C++ programmers with its technical low-level calls. Data Access Objects (DAO) was developed by Microsoft to provide a way for Visual Basic developers to simplify data access. It enabled programs that do not use pointer type address variables to connect to Access databases (Access is also known as the Jet Engine). To use other databases, like SQLBase, DAO utilized the ODBC and Jet Engine as shown in Figure 2:

Page 6: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Figure 2 - DAO Architecture

RDO

To access a wide variety of relational databases using DAO, Jet Engine had to translate calls between DAO and ODBC, introducing a performance penalty. To overcome this limitation, Microsoft introduced Remote Data Objects (RDO). RDO accesses ODBC without going through Jet Engine as shown in Figure 3:

Page 7: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Figure 3 - RDO Architecture

OLE DB

Over the years, ODBC worked well in connecting to relational databases. As more and more data is stored in non-relational format, as Microsoft Exchange Server does, a new architecture was needed to provide seamless connectivity across various data sources and applications. OLE DB was the fundamental Component Object Model (COM) building block for storing and retrieving records and provides consistent access to relational databases, non-relational, and unstructured data sources across the enterprise. OLE DB was introduced to build upon the success of ODBC. The architecture is shown in Figure 4:

Figure 4 - OLE DB Architecture

Page 8: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

ADO

OLE DB utilizes several technical low-level calls that can make programming tedious, especially for Visual Basic type of programs. To overcome this problem, Microsoft introduced ActiveX Data Objects (ADO). ADO works on top of OLE DB providing a simpler, higher-level interface, as shown in Figure 5:

Figure 5 - ADO Architecture

Understanding the differences between ADO and ADO.NET ADO is based on the Microsoft COM architecture with OLE DB interfaces, whereas ADO.NET is based on the Microsoft .NET architecture and specific ADO.NET interfaces. Since the .NET architecture is completely different from the COM architecture, ADO.NET interfaces are completely different from the ADO and OLE DB interfaces. This also means that ADO.NET data providers are completely different technology from the ADO data providers.

How is ADO.NET different from ADO? When it started designing the .NET architecture, Microsoft decided to redesign the data access model. Rather than extending ADO further, Microsoft decided to design a new data access architecture based on the new .NET framework—but, Microsoft kept the acronym ADO involved anyway. Microsoft designed ADO.NET based on its experience with its successful ADO object model, but with a completely different architecture based on XML and a disconnected computing model. The new architecture provides several ways an application can connect to a data source as shown in Figure 6:

Page 9: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Figure 6 - ADO.NET Architecture

To understand the evolution to ADO.NET, it is important to recognize some of the ADO-based issues that lead to its design. ADO uses Recordsets and cursors to access and modify data. Because of its inherent design, Recordset can impact performance on the server side by tying up valuable resources. In addition, COM marshalling - an expensive data conversion process - is needed to transmit a Recordset. Microsoft tried to improve the design by adding XML support starting with ADO 2.1. However, the XML support is not robust and the XML usage is bound by several limitations.

ADO.NET addresses three important needs that ADO doesn't address:

1. Providing a comprehensive disconnected data-access model, which is crucial to the Web environment

2. Providing tight integration with XML, and

3. Providing seamless integration with the .NET Framework (e.g., compatibility with the base class library's type system).

From an ADO.NET implementation perspective, the Recordset object in ADO is eliminated in the .NET architecture. In its place, ADO.NET has several dedicated objects led by the DataSet object and including the DataAdapter, and DataReader objects to perform specific tasks. In addition, ADO.NET DataSets operate in disconnected state whereas the ADO RecordSet objects operated in a fully connected state.

Because of the fundamental differences in COM and .NET (and therefore fundamental difference in ADO and ADO.NET architecture), a completely new technology is

Page 10: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

needed in ADO.NET for accessing data from the .NET platform. In fact, this eliminates the need for the existing ADO data provider technology.

Whereas a COM-based ADO data provider would have been developed in C++ with COM libraries, the ADO.NET data provider is required to be written with only the .NET Framework base class libraries and is designed to work completely within the parameters of Common Language Runtime (CLR). In addition, the ADO.NET environment is designed by default to work with data in XML format rather than native OS types of ADO.

Summary ADO.NET leverages XML to provide optimized data access for the .NET framework. Since the base architectures from COM and .NET are fundamentally different, ADO.NET data providers are completely different products from the older ADO data providers. Organizations looking to migrate to .NET and that care about functionality and performance will need to invest in new ADO.NET data providers.

Page 11: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

SQLBase ODBC driver

The SQLBase ODBC driver supports the Gupta SQLBase database system in the following operating systems: Windows 98, ME, NT (4.0 and higher), 2000, and XP. The driver file name is sqlbaseodbc.dll. The driver and data source configuration are done through sqlbaseodbcsetup.dll.

System requirements To communicate with the server, the SQLBase driver requires SQLWNTM.DLL, SQLABPW.DLL, SQLBASEUTIL.DLL, and a communication DLL (for example, SQLWS32.DLL, for TCP/IP). The directory containing these files must be on your path. Client applications written with the Gupta programming tool, SQLWindows, cannot use ODBC to connect to SQLBase. The ODBC driver makes multiple recursive calls into the SQLBase API, and the driver and application interfere with each other. For such applications, use the native SQLBase routers instead.

ODBC Conformance Level

The driver conforms to ODBC level 1 completely. In addition, many level 2 functions and some level 3 functions are supported. The driver conforms to Entry-level SQL, and several Full level SQL features are also supported. The driver also supports backward and random fetching in SQLExtendedFetch and SQLFetchScroll.

Number of Connections and Statements Supported

The SQLBase database system supports multiple connections and multiple statements per connection.

Isolation and Lock Levels Supported SQLBase supports the following standard ODBC isolation levels: SQL_TXN_REPEATABLE_READ, SQL_TXN_READ_COMMITTED and SQL_TXN_READ_UNCOMMITTED. SQLBase supports page-level locking.

Configuring Data Sources To configure a SQLBase data source, do the following: 1.Start the ODBC Administrator to display a list of data sources. 2.If you are configuring an existing data source, select the data source name and click Configure to display the SQLBase Data Source Properties dialog box. If you are configuring a new data source, click Add to display a list of installed drivers. Select Gupta SQLBase and click Finish to display the SQLBase Data Source Properties dialog box. 3.Specify a data source name, a database name and optionally, a description. Click Apply. 4.Click Test Connect to attempt to connect to the data source using the connection properties specified in the Driver Setup dialog box. 5.If desired, configure optional data source settings in the Advanced section of the dialog. 6.Click OK or Cancel. If you click OK, the values you have specified become the defaults when you connect to the data source. You can change these defaults by

Page 12: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

using this procedure to reconfigure your data source. You can override these defaults by connecting to the data source using a connection string with alternate values.

Data Source Properties dialog

Use the ODBC SQLBase Data Source Configuration dialog box to create new SQLBase data sources or configure existing data sources.

Data Source Name: A string that identifies this SQLBase data source configuration in the system information. Examples include "Accounting" or "SQLBase-Serv1." Description: An optional long description of a data source name. For example, "My Accounting Database" or "SQLBase on Server number 1." Database Name: The name of the database to which you want to connect by default. Isolation Level: The method of locking to use for this connection. Choices are Release Locks, Read Repeatability, Read Only, or Cursor Stability. For detailed information about how these levels work, read the SQLBase Language Reference manual, specifically the SET ISOLATION command. Input Message Size: The number of bytes in the input message buffer. SQLBase determines the default. Increasing this value retrieves more records across the network in a single fetch. Lock Timeout: The number of seconds SQLBase should wait for a lock to be freed before raising an error. Values can be -1 (wait forever) to 1800;the default is 300.

Page 13: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Config Filename (INI): The file which will be used to get information about available servers, databases, and protocols. You can leave this blank and let SQLBase choose the default file, or you can type or browse for a file name.

Connection strings If your application requires a connection string to connect to a data source, you must specify the data source name that tells the driver which section of the odbc.ini file to use for the default connection information. Optionally, you may specify attribute or value pairs in the connection string to override the default values stored in the odbc.ini file. You can specify either long or short attribute names in the connection string. Gupta recommends that you use long names. The connection string has the following format: DSN=data source name [;attribute=value [;attribute=value ]...] An example of a connection string for SQLBase is: DSN=SQLBASE_TABLES;SRVR=QESRVR;DB=PAYROLL; UID=JOHN;PWD=XYZZY;

Connection string keywords

Driver: Used in DSN-less connections, and is required to tell the Driver Manager which ODBC driver the rest of the connection string pertains to. DataSourceName (DSN): A string that identifies a single connection to a SQLBase database system, for example, "Accounting". Database (DB): The name of the database system to which you want to connect. ServerName (SRVR): The name of the server that hosts the database to which you want to connect. LogonID (UID): The default Logon ID used to connect to your SQLBase system. A Logon ID is required only if security is enabled on your database system. If so, contact your system administrator to get your Logon ID. This value is case-sensitive. Password (PWD): Case-sensitive password. IsoLevel (IL): A string that specifies how SQLBase will handle locking for this connection. Possible values are RL (Release Locks), RR (Read Repeatability),RO (Read-Only), and CS (Cursor Stability).For detailed information about how these levels work, read the SQLBase Language Reference manual, specifically the SET ISOLATION command. InputMessageSize (IMS): Controls the number of bytes of the input message buffer. Increasing this value retrieves more records across the network in a single fetch. LockTimeOut (LTO): Number of seconds SQLBase waits for a lock to be freed before raising an error. Values can be -1 to 1800.A value of -1 is infinite wait. Default is 300. NoRecovery (NR): This keyword is accepted for backwards compatibility, but has no effect on the SQLBase server.

Page 14: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Logon dialog

Your application might supply enough information in the connection string to make the connection without prompting you. If not, when the SQLBase ODBC Driver needs additional information from you to make a connection, it displays a dialog box. Fill out the values in the dialog box as shown below:

1.Optionally, type the name of the server containing the SQLBase database tables you want to access or select the name from the Server Name drop-down list box, which displays the server names you specified in the Setup dialog box. Type Local to access a local SQLBase database. 2.Type the name of the database you want to access. If you specified a server name, you can select the name from the Database Name drop-down list box. 3.If required, type your user name. 4.If required, type your password. Click OK to complete the logon and to update the values in the system information.

Page 15: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

SQLBase OLE DB Data Provider

Overview OLE DB is an application-programming interface, written by Microsoft. Part of Microsoft ’s Universal Data Access strategy, it aims to facilitate access to information across data sources. The goal is to reliably offer high-performance data access that supports industry standards. The Universal Data Access strategy addresses the technical obstacles organizations face when trying to disseminate information across client/server networks and the World Wide Web. This task becomes more of a challenge given multiple platforms, legacy systems, and numerous programming languages and development tools. Based on open industry specifications, Universal Data Access allows developers to extend the capabilities of existing technologies. OLE DB fits into this strategy by giving developers the ability to write applications that have uniform access to data regardless of the data source and development tool. Using OLE DB, it is possible for different pieces of an application to be written in different languages due to OLE DB ’s COM structure.

OLE DB components

The two main components of OLE DB are a data provider and a data consumer. An OLE DB data provider responds to OLE DB calls resulting in data being returned in a usable tabular format. A data consumer is an application or COM component that uses the OLE DB API to access a data source. Since OLE DB comprises a set of Component Object Model (COM) interfaces, it results in a high level of interoperability among programming tools. The COM interfaces support the full DBMS functionality of the data source. The COM specification allows you to use a variety of programming tools, such as Gupta SQLWindows, Visual Basic and Delphi, to develop application components that can function within a single application.

Recommended reading

To make the best use of OLE DB, we recommend that you read Microsoft OLE DB 2.0 Programming Reference and Data Access SDK.

About SQLBase OLE DB Data Provider Built upon OLE DB technology, SQLBase OLE DB Data Provider lets programmers access SQLBase functionality from a variety of supported visual programming tools. Historically, developers have had to call SQL/API functions or use the ODBC API to access a database. SQLBase OLE DB Data Provider exposes SQLBase Server properties more completely than the ODBC driver does, allowing developers to directly interface with the database and server using a variety of programming tools. SQLBase OLE DB Data Provider is a set of COM objects that expose the SQLBase functionality needed by developers to build applications. In addition to standard OLE DB conformance, the Provider interfaces enable access to DBMS functionality not normally provided by OLE DB, including backup, create database, and shutdown server. A DLL, SQLBase OLE DB Data Provider runs in the address-space of the client program and is written over the SQL/API. Using OLE DB interfaces, the Provider lets

Page 16: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

one define DBMS components, including row containers, query processors, and transaction coordinators. The following figure shows the role of SQLBase OLE DB Data Provider in the application development process.

SQLBase OLE DB Data Provider name

When you configure a programming tool to use the Provider, you may need to enter a provider name. For SQLBase OLE DB Data Provider, the name is: SQLBaseOLEDB

The provider string is initialized for the open call that establishes a connection to SQLBase through the OLE DB provider. The name of the SQLBase OLE DB provider is hard-coded as a constant. The user ID, password, location and data source (tablename) are read from objects in your code. Here is a sample: Dim sConnect As String ' holds ADO connect string ' set up connection string and open connection to data source sConnect = "Provider=SQLBASEOLEDB.1" _

Page 17: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

& ";Data Source=ISLAND" _ & ";User ID=SYSADM" _ & ";Password=SYSADM"

Data source name Some programming tools may prompt you for a data source name. For SQLBase OLE DB, the data source name is the name of the SQLBase database itself (for example, ISLAND).

Supported programming tools SQLBase OLE DB Data Provider is designed to work with the following programming tools: Gupta Team Developer (SQLWindows), all the languages of Microsoft ’s Visual Studio, Delphi, Crystal Reports, PowerBuilder, and many others. In general, SQLBase OLE DB Data Provider works with any development environment that supports OLE DB data access.

Installing

SQLBase OLE DB Data Provider is an option in the overall SQLBase installation. There is a checkbox for “OLE DB Data Provider ” in the “Client Components ” section of the installer.

Page 18: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Using ADO

This section introduces you to the basics of ActiveX Data Objects (ADO) and how to use it. The second section of this chapter includes a coding example that shows you how to use SQLBase OLE DB Data Provider and ADO. To make the best use of ADO, we recommend you access the samples in: www.microsoft.com/data and access further information on ADO in: www.microsoft.com/data/ado

ADO Overview

Microsoft ActiveX Data Objects (ADO) enables you to write an application to access and manipulate data in a database server through an OLE DB provider, such as the SQLBase provider. ADO's primary benefits are data source independence, high speed, ease of use, low memory overhead, and a small disk footprint. Since ADO is independent of the data source, you do not have to know all the intricacies of the database to take advantage of the provider. For more general information about OLE DB providers, see the documentation for the Microsoft OLE DB SDK or visit the Microsoft OLE DB Web page. The SQLBase OLE DB Data Provider is a standard provider you can use with ADO as you would other standard providers.

ADO features ADO provides a number of features for building client/server and Web-based applications. Using the SQLBase provider with ADO, you can take advantage of:

Independently created objects. Unlike Data Access Objects (DAO) or Remote Data Objects (RDO), you no longer have to navigate through a

hierarchy to create objects because most ADO objects can be independently created. This allows you to create and track only the objects you need, and also results in fewer ADO objects and thus a smaller working set. Batch updating. If you are using client-side cursors, you can do batch

updating. This helps improve performance by locally caching changes to data, then writing them all to the server in a single update. Support for stored procedures with input (not output) parameters. Different cursor types, including support of backend –specific cursors.

With the SQLBase provider, when the user asks for the ability to fetch backward or scroll backward, the provider asks the server to enable its cursors.

Remote Data Service

ADO's Remote Data Service (RDS) allows data remoting, by which you can move data from a server to a client application or Web page, manipulate the data on the client, and return updates to the server in a single round trip. Previously released as Advanced Data Connector, RDS has been combined with the ADO programming model to simplify client-side data remoting.

Page 19: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

As part of the Microsoft Data Access Components, ADO and RDS are automatically installed and registered by a host product, such as Microsoft Internet Information Server. The host product setup program may require that you specifically request the Microsoft Data Access Components in order to have ADO and RDS installed.

Programming with ADO

ADO is a dual-interface COM type library. The file name is msado27.dll. The program ID (ProgID) is "ADODB." In two-and three-tier database applications, ADO code that is to execute on the client uses the ProgID "ADOR" instead. To use ADO with Microsoft Visual Basic or Microsoft Office, you also need to establish a reference to the ADO type library. From the Project menu, select References, check the box for "Microsoft ActiveX Data Objects 2.7 Library," and then click OK. ADO objects, methods, and properties will then be accessible through the VBA Object Browser and the IDE Editor.

To use ADO with Microsoft Visual J++, you also need to create a set of class files using the Java Type Library Wizard. From the Tools menu, select the Java Type Library Wizard, check the box for "Microsoft ActiveX Data Objects 2.7 Library," and then click OK .The wizard will then create the necessary Java class files for ADO. For some programming languages, you also need to reference (using the #include statement) one or more additional files in your source code, as shown here:

C++ VBScript JScript adoint.h adoid.h

Adovbs.h Adojavas.inc

Page 20: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Threading

With SQLBase OLE DB Data Provider, use ADO as apartment-model threaded.

ADO Objects

Although you create ADO objects outside the scope of a hierarchy, the objects exist within hierarchical relationships, as shown in the ADO Object Model. There are seven objects in the ADO object model: Command — Maintains information about a command, such as a query string, parameter definitions, and so on. You can execute a command string on a Connection object or a query string as part of opening a Recordset object, without defining a Command object. The Command object is useful where you want to define query parameters, or execute a stored procedure that returns output parameters. Connection — Maintains connection information with the data provider. Error — Contains extended error information about an error condition raised by the provider. Because a single statement can generate two or more errors, the Errors collection can contain more than one Error object at a time, all of which result from the same incident. Field — Contains information about a single column of data within a Recordset. The Recordset object features a Fields collection to contain all of its Field objects. Parameter — A single parameter for a parameterized Command. The Command object features a Parameters collection to contain all of its Parameter objects. Property — A provider-defined characteristic of an ADO object. Recordset — A set of records returned from a query, and a cursor into those records. You can open a Recordset (that is, execute a query) without explicitly opening a Connection object. However, if you do first create a Connection object, you can open multiple Recordset objects on the same connection. Cursor —In ADO, this is the equivalent of a recordset. Each of these objects features a set of properties and methods with which you can manipulate the object and its contents.

Dynamic Properties Collections

The Connection, Command, and Recordset objects each support a Properties collection. The properties collection contains any dynamic (or "provider-specific") properties exposed through ADO by the SQLBase provider. You use the collection and the Item method to reference the property by its name or by its ordinal position in the collection, as shown: Command.Properties.Item(0) Command.Properties.Item("Name") Because the Item method is a default method on an ADO collection, you can omit it: Command.Properties(0) Command.Properties("Name") Further, the Properties collection itself is the default collection for the Connection, Command, and Recordset objects, so you can omit it as well: Command(0) Command("Name")

Page 21: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

All of these syntax forms are identical. Which one you choose depends on your coding style preference.

Working with Data In ADO, the Recordset object is the main interface to data. While the other objects are useful for managing connections, collecting error information, persisting queries, and so on, most of your code's interaction with ADO will involve one or more Recordset objects. This Microsoft Visual Basic Scripting code generates a Recordset from a SQLBase data source: set rstMain = CreateObject("ADODB.Recordset") rstMain.Open "SELECT * FROM company", _ "Provider=SQLBaseOLEDB;Data source=ISLAND" The first line creates the ADO Recordset object. The second line opens the recordset with a query. The third line specifies the SQLBase provider and the data source. This generates a forward-only, read-only Recordset object. With a few modifications, you can obtain a more functional Recordset: set rstMain = CreateObject("ADODB.Recordset") rstMain.Open "SELECT * FROM company", _ "Provider=SQLBASEOLEDB.1; Data source=ISLAND", adOpenKeyset, adLockBatchOptimistic This creates a fully scrollable and batch-updateable Recordset. In order to reference ADO constants by name (instead of by value) when coding in a scripting language, as shown in these code examples, you must include the appropriate header file. For Microsoft Visual Basic Scripting code, include the file adovbs.inc in your code. For Microsoft JScript, include the file adojavas.inc in your code. You should always refer to constants by name rather than by value because the values may change from one version to the next. However, because each provider is unique, how your application interacts with ADO will vary slightly between different providers. The differences you need to be aware of when using SQLBase OLE DB Data Provider are:

Connection parameters in the ConnectionString property Command object usage. Recordset behavior.

SQLBase provider-specific dynamic properties The Properties collections of the Connection, Command, and Recordset objects include dynamic properties specific to the SQLBase provider. These properties provide information about functionality beyond the built-in properties ADO supports. After establishing the connection and creating these objects, use the Refresh method on the object's Properties collection to obtain the SQLBase provider-specific properties.

Page 22: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Sample applications

The SQLBase provider comes with a number of sample applications. These samples have been developed to show some of the ways ADO can be used with Visual BASIC to communicate with the SQLBase database product.

simplefetch Lets you connect to SQLBase and navigate, forward and backwards, through the COMPANY table -part of the ISLAND sample database for SQLBase. schema

Lets you query the ADO schema types that the SQLBase OLE DB Data Provider supports. DBExplore

Lets you query SQLBase using SQL statements to return Recordsets from the SQLBase database. DBExplore.exe pulls out a Long Binary set of information, processes it, and writes it out to a file. Long text fields and Long Binaries are treated the same by the provider. SqlBaseNativeCmdSample

Demonstrates the SQLBase Native commands (load, unload, store, erase and retrieve).

You must have installed Microsoft Visual Basic 6.0,the Microsoft Data Access components and the SQLBase OLE DB Data Provider in order to use these samples.

Connecting to data through the Provider Whether or not you use ADO or direct OLE DB, you acquire database information using these steps: 1.Initialize the provider. 2.Establish a connection. 3.Open a recordset object. 4.Navigate through the database. 5.Process the recordset. 6.Disconnect.

Page 23: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

.NET Data Provider

SQLBase .NET implementation The current version of SQLBase provides objects that implement eight of the .NET interfaces. SQLBaseConnection: implements the IDbConnection interface, establishes a connection to a specific data source. SQLBaseCommand: implements the IDbCommand interface, executes a command against a data source, exposes parameters and can execute within the scope of a Transaction. SQLBaseDataReader: implements the IDataReader interface and reads a forward- only, read-only stream of data from a data source. SQLBaseDataAdapter: implements the IDataAdapter interface; populates a DataSet and resolves updates with the data source. SQLBaseTransaction: implements the IDbTransaction interface and represents a transaction to be performed at a data source. SQLBaseParameter: implements the IDataParameter interface, represents a parameter that can be passed to a SQL command. SQLBaseParameters: implements the IDataParameters interface, which is a simple collection of SQLBaseParameter objects. In addition to these eight objects, SQLBase provides SQLBaseException, a public interface/object that is used for throwing exceptions to a client in case of a SQLBase error during a client method call.

Connection pooling in the Connect method

SQLBase provides the last two keywords in the connection string parameter of the Connect method to assist with connection pooling. poolsize indicates how many SQLBase connections should be kept open, whether they are in immediate use or not. The default value is 5. connection lifetime indicates how long each connection should be maintained, in seconds. The default value is 60. These defaults are stored in the Windows registry under key HKEY_CURRENT_USER\Software\Gupta\SQLBase\DotNetDataProvider Each connection pool is specific to the application that calls the Connect method. When the number of active connections is still below or at the poolsize limit, connections that have been closed by the application remain cached (physically open and available for new connection requests) until their lifetime is reached, at which time they are physically disconnected. Connections that are enlisted in transactions remain open until the transaction is committed or rolled back. Each call to Connect resets the current values for poolsize and connection lifetime. Gupta recommends that you avoid issuing Connect calls in which the new value for poolsize is smaller than the one currently being used by the application.

SQLBaseCommand object SQLBase supports three types of command objects: Text Command, Stored Procedure, and Table Direct. The default type of each command, upon creation, is

Page 24: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Text Command .You are responsible for changing this type, if necessary, by altering the CommandType property of the object. You should set the value of the CommandText property of the object before any other methods are called. For a Text Command type, the CommandText property should contain a valid SQL statement. For a Stored Procedure type, the CommandText property should contain a procedure name. For a Table Direct type, the CommandText property should contain a table name.

SQLBaseDataReader object This object provides the capability of reading a forward-only result set obtained by executing a command against a data source. SQLBase supports only a single result set. Datatypes are mapped to CLR-compatible types as described in Mapping SQLBase Datatypes to Common Language Runtime.

SQLBaseDataAdapter object The methods of this class are all inherited from the standard DbDataAdapter class, which can be found in the .NET Framework documentation. To complete the functionality of this class, SQLBase must implement four properties that are found in the DbDataAdapterInterface. Each of these properties has Get and Set methods.

Page 25: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Tutorials

Getting Started Each SQLBase 9.0 installation on a computer now uses a separate configuration file (default name sql.ini). You have control over the name and path of the configuration file. You can also control the location of binary components required for the server and client. Multiple SQLBase engines can run simultaneously.

The SQLBase OLEDB Data Provider now supports optionally specifying a configuration file through property DBPROP_INIT_PROVIDERSTRING in the following format:

INI=<Configuration File Name with full path>

(You may also specify the string in the UDL/Data Link property dialog box. The configuration file name with the above format could be entered as a value for "Extended Properties" in the "All" page.) Using these features allows you to connect via OLEDB to databases on more than one server machine. Earlier versions of the provider permitted connections to only one server machine.

The SQLBase .NET Data Provider now allows you to specify a configuration filename in the connection string. An example of such a connection string is:

SQLBaseConnection conn = new SQLBaseConnection("data source=island; uid=sysadm; pwd=sysadm; ini=D:\\Gupta\\SQLBase 9.0\\sql.ini");

The SQLBase ODBC Driver "Gupta SQLBase Data Source Properties" dialog box has been extended to allow you to optionally enter the configuration filename.

Note: All tutorials have a hard-coded configuration file location – d:\Gupta\SQLBase 9.0\sql.ini. You will have to change this to the location of your sql.ini file.

Visual Basic v6.0 Tutorials

Tutorial 1 This tutorial will walk you through creating code for connecting to the SQLBase Island database using ODBC and ADO. We will then create a simple single table form, populating TextBoxes. We will include code that allows you to step forward and backward through data, go to the last record and go to first record.

1. Start Visual Basic 2. Create a new Standard EXE

Page 26: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

3. Add the included Module from \Module\FuncAdo.bas to the project

Page 27: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

The code for this module is explained by the comments below:

Option Explicit ' Create an instance of the common class Public myADO As New adoGupta ' Main Sub Public Sub main() ' Loads the Logon form Load frmLOGON ' Shows the Logon form as a modal dialog frmLOGON.Show (vbModal) ' Check the Logon State If myADO.logonState = True Then frmSearch.Show (vbModal) Else Call MsgBox("Logon Failed", vbInformation + vbOKOnly, "SQLBase Tutorial") End If End Sub

4. Add the included Class Module from \Class\ado.cls to the project

Page 28: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

The code for this class is explained by the comments below:

Option Explicit Private sConnect As String ' connect string Private bLogonState As Boolean ' logon state Private sUser As String ' user id Private sPWD As String ' password Private sDSN As String ' data source name Private sSelect As String ' SELECT statement storage Private sUpdate As String ' UPDATE statement storage Private sInsert As String ' INSERT statement storage Private iCursorType As Integer ' cursor type for connection Private iLockType As Integer ' lock type for connection Private oAdoConn As New ADODB.Connection ' Global Connection Object Private oAdoRS As New ADODB.Recordset ' Global RecordSet Object ' Function to set up the database connect string Private Function BuildConnectString(dsn As String) As String On Error GoTo CheckError sConnect = dsn & ";UID=" & sUser & ";PWD=" & sPWD

Page 29: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

BuildConnectString = sConnect FunctionExit: Exit Function CheckError: Resume Next BuildConnectString = "" Resume FunctionExit End Function ' UserName Get/Set Properties Public Property Get user() As String user = sUser End Property Public Property Let user(sUserIn As String) If Len(sUserIn) < 1 Then sUser = "SYSADM" Else sUser = UCase(sUserIn) End If End Property ' Password Get/Set Properties Public Property Get pwd() As String pwd = sPWD End Property Public Property Let pwd(sPwdIn As String) If Len(sPwdIn) < 1 Then sPWD = "SYSADM" Else sPWD = UCase(sPwdIn) End If End Property ' Logon State Get/Set Properties Public Property Get logonState() As Boolean logonState = bLogonState End Property Private Property Let logonState(bLogStateIn As Boolean) bLogonState = bLogStateIn End Property ' Data Source Name Get/Set Properties Public Property Get dsn() As String dsn = sDSN End Property Public Property Let dsn(sDSNIn As String) If (Len(sDSNIn) < 1) Then sDSN = "SQLBase Island Database" Else

Page 30: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

sDSN = UCase(sDSNIn) End If End Property ' Database Connect function Public Function connect() As Boolean Dim er As ADODB.Error Dim sMsg As String On Error GoTo CheckError BuildConnectString (sDSN) Screen.MousePointer = vbHourglass oAdoConn.ConnectionString = sConnect oAdoConn.Open logonState = True FunctionExit: Screen.MousePointer = vbDefault Exit Function CheckError: On Error Resume Next sMsg = Err.Description & vbCrLf If Not oAdoConn Is Nothing Then For Each er In oAdoConn.Errors sMsg = sMsg & er.Description & vbCrLf Next End If MsgBox "Connection Failed. " & vbCrLf & sMsg Resume FunctionExit End Function ' SQL Select function Public Function doSelect(sDQL As String) As Boolean If Len(Trim(sDQL)) > 0 Then sSelect = sDQL If oAdoRS.state = adStateOpen Then oAdoRS.Close End If Call oAdoRS.Open(sSelect, oAdoConn, iCursorType, iLockType) doSelect = True Else doSelect = False End If End Function ' SQL Update Function

Page 31: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Public Function doUpdate(sDQL As String) As Boolean If Len(Trim(sDQL)) > 0 Then sUpdate = sDQL oAdoConn.BeginTrans Call oAdoConn.Execute(sUpdate) oAdoConn.CommitTrans doUpdate = True Else doUpdate = False End If End Function ' Returns the current Resultset Public Function getRS() As ADODB.Recordset Set getRS = oAdoRS End Function ' Class destructor Private Sub Class_Terminate() If Not oAdoRS Is Nothing Then If oAdoRS.state = adStateOpen Then oAdoRS.Close End If End If If Not oAdoConn Is Nothing Then If oAdoConn.state = adStateOpen Then oAdoConn.Close End If End If End Sub ' Set Lock Type Public Function setLockType(iRT As Integer) If (iRT >= adLockReadOnly) And (iRT <= adLockBatchOptimistic) Then iLockType = iRT Else iLockType = adLockReadOnly End If End Function ' Set Cursor Type Public Function setCursorType(iRT As Integer) If (iRT >= adOpenForwardOnly) And (iRT <= adOpenStatic) Then iCursorType = iRT Else iCursorType = adOpenForwardOnly End If End Function ' Get number of errors Public Function getErrorCount() As Integer

Page 32: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

getErrorCount = oAdoConn.Errors.Count End Function ' Get actual errors Public Function getErrors() As ADODB.Errors Set getErrors = oAdoConn.Errors End Function

5. Now design the Logon form to look something like the following:

Object Name Form frmLOGON TextBoxes txtUserName

txtPassword Command Buttons cmdOK

cmdCancel

6. Add the following code to the form:

Option Explicit ' This sets the TextBoxes with the default UserName and Password Private Sub Form_Load() txtPassword.Text = "SYSADM" txtUserName.Text = "SYSADM" cmdOK.Enabled = True End Sub ' This is called when either the UserName or Password is changed Private Sub CheckOK() If txtPassword = vbNullString Or txtUserName = vbNullString Then cmdOK.Enabled = False Else cmdOK.Enabled = True End If End Sub ' This unloads the form and quits the application Private Sub cmdCancel_Click() Unload Me End Sub ' Triggered when the Ok button is clicked

Page 33: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Private Sub cmdOK_Click() ' Set the user and pwd properties myADO.user = txtUserName myADO.pwd = txtPassword ' Pass in the default Data Source Name myADO.dsn = "DSN=SQLBase Island Database" ' Call the connect method Call myADO.connect ' Unload the form Unload Me End Sub ' Triggered when the UserName TextBox is changed Private Sub txtUserName_Change() CheckOK End Sub ' Triggered when the Password TextBox is changed Private Sub txtPassword_Change() CheckOK End Sub

7. Now save this project as VB_TUT1.

8. Next we are going to create a form that looks like the following:

Object Name Form frmSearch TextBoxes txtEmployee (all 5) Query Command Buttons cmdFind

cmdClearFields Close Command Button cmdClose Navigation Command Buttons cmdNavigate (all 4) Label LblStatus

Page 34: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

9. Now add the following code to the form:

The comments in the code explain the code.

Option Explicit Private iFormState As Integer ' Constants to determine the state of the form Const fsNone = 0 Const fsEdited = 1 Const fsFound = 3 Const fsAddNew = 5 ' Function to process errors Private Function ProcessErrors(ErrorAt As String) Dim er As ADODB.Error Dim sMsg As String sMsg = "A serious error occurred in the " & ErrorAt & " Module. " & vbCrLf sMsg = sMsg & Err.Description MsgBox sMsg If myADO.getErrorCount > 0 Then sMsg = "Additional errors occurred in the " & ErrorAt & " Module. " & vbCrLf For Each er In myADO.getErrors sMsg = sMsg & " " & er & vbCrLf Next MsgBox sMsg End If End Function 'Sets the form's state Private Sub SetFormState(state As Integer) iFormState = state End Sub 'Sets the Status label and disables/enables buttons appropriately Public Sub SetFormUI() Dim iCount As Integer Select Case iFormState Case 0 ' Start Fresh after form start-up or clear For iCount = 0 To 3 cmdNavigate(iCount).Enabled = False Next iCount cmdFind.Enabled = True cmdClearFields.Enabled = False LblStatus.Caption = "Browse Employees" Case 1 'Edit

Page 35: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

For iCount = 0 To 3 cmdNavigate(iCount).Enabled = False Next iCount cmdFind.Enabled = True cmdClearFields.Enabled = True LblStatus.Caption = "Enter criteria for Search" Case 2 'Unknown Case 3 'Found For iCount = 0 To 3 cmdNavigate(iCount).Enabled = True Next iCount cmdFind.Enabled = False cmdClearFields.Enabled = True LblStatus.Caption = "Navigate Result Set" Case 4 'Edit, Found For iCount = 0 To 3 cmdNavigate(iCount).Enabled = False Next iCount cmdFind.Enabled = False cmdClearFields.Enabled = True LblStatus.Caption = "Editing current employee " Case Else 'Don’t have a clue End Select End Sub ' The SQL Select statement for employee records Function BldEmpQuery() As String Dim strSQL As String BldEmpQuery = "SELECT EMPLOYEE_ID, LAST_NAME, FIRST_NAME, EMAIL, CURRENT_SALARY FROM EMPLOYEE" End Function ' Creates the Employee Recordset Function CreateEmployeeSet(strSQL As String) As Boolean Dim myRS As ADODB.Recordset On Error GoTo CheckError myADO.setCursorType (adOpenKeyset) myADO.setLockType (adLockOptimistic) myADO.doSelect (strSQL) Set myRS = myADO.getRS If Not myRS.BOF And Not myRS.EOF Then

Page 36: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

myRS.MoveFirst End If FunctionExit: Exit Function CheckError: ProcessErrors ("Record Set Creation ") Resume Next Resume FunctionExit End Function ' Sets Employee connection state Function SetEmpCon() As Boolean On Error GoTo CheckError SetEmpCon = True FunctionExit: Exit Function CheckError: ProcessErrors ("DB Connection ") Resume FunctionExit End Function ' Sets up variables and Cursor/Lock Types Public Sub SetupForm() Dim myRS As ADODB.Recordset Dim strSQL As String Dim iCount As Long Dim cType As Integer On Error GoTo CheckError myADO.setCursorType (adOpenStatic) myADO.setLockType (adLockOptimistic) SubExit: Exit Sub CheckError: ProcessErrors ("Form Setup / ListBox population ") Resume SubExit End Sub ' Populates the TextBoxes Public Sub ShowRecord() Dim myRS As ADODB.Recordset Dim icol As Integer Dim iCount As Integer

Page 37: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Set myRS = myADO.getRS For icol = 0 To 4 txtEmployee(icol) = myRS(icol) txtEmployee(icol).DataChanged = False Next icol SetFormState (fsFound) End Sub ' Close the form when menu item clicked Private Sub Close_Click() Unload Me End Sub ' Clear all TextBoxes Private Sub cmdClearFields_Click() Dim iCount As Integer For iCount = 0 To 4 txtEmployee(iCount) = vbNullString txtEmployee(iCount).DataChanged = False Next iCount txtEmployee(0).Enabled = True SetFormState (fsNone) SetFormUI End Sub ' Close the form when command button clicked Private Sub cmdClose_Click() Unload Me End Sub ' Processing for the Find button Private Sub cmdFind_Click() Dim myRS As ADODB.Recordset Dim strSQLSelect As String Set myRS = myADO.getRS strSQLSelect = BldEmpQuery CreateEmployeeSet (strSQLSelect) If myRS.EOF Or myRS.BOF Then MsgBox "No rows found matching your query..." Else SetFormState (fsFound) SetFormUI ShowRecord End If End Sub ' Processing for the Navigation buttons Private Sub cmdNavigate_Click(Index As Integer) Dim myRS As ADODB.Recordset

Page 38: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Set myRS = myADO.getRS Select Case Index Case 0 myRS.MoveFirst Case 1 myRS.MovePrevious If myRS.BOF Then Beep myRS.MoveFirst End If Case 2 myRS.MoveNext If myRS.EOF Then Beep myRS.MoveLast End If Case 3 myRS.MoveLast End Select ShowRecord End Sub ' Form load processing Private Sub Form_Load() Call SetupForm Call SetEmpCon Call SetFormState(fsNone) SetFormUI Screen.MousePointer = vbDefault End Sub

10. Now save the project and run.

11. Click on the OK button to Logon to the Database, click on Find, and use the

Navigation buttons to scroll through the result set

Page 39: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Tutorial 2 This Tutorial expands on Tutorial 1, allowing one to query by placing a partial name in a field and using the soundex() function to retrieve data. This Tutorial also shows you how to update and save data to the database.

1. Start Visual Basic 2. Open the Project \Tut1\VB_TUT1, and save it as \Tut2\VB_TUT2 3. Save the form \Tut1\frmSEARCH.frm as \Tut2\frmSEARCH2.frm 4. Change the name of the Project in the properties section to VB_TUT2 as

indicated

Page 40: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

5. Now resize the form frmSearch to add a Label and TextBox and the Save button as illustrated:

Page 41: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Object Name TextBox txtSearch Save Command Button cmdDML

6. Add the following function to the code for the form:

' Setup the where clause with the @soundex() function

Function bldWhere() As String

If txtSearch(0) <> vbNullString Then

bldWhere = bldWhere & "@SOUNDEX(LAST_NAME) = " & "@SOUNDEX('" & txtSearch(0).Text & "')"

End If

If bldWhere <> vbNullString Then

bldWhere = " Where " & bldWhere

End If

End Function

7. Add the line in red to the BldEmpQuery function

' The SQL Select statement for employee records

Function BldEmpQuery() As String

Dim strSQL As String

Page 42: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

BldEmpQuery = "SELECT EMPLOYEE_ID, LAST_NAME, FIRST_NAME, EMAIL, CURRENT_SALARY FROM EMPLOYEE"

BldEmpQuery = BldEmpQuery & bldWhere

End Function

8. Add the following code for the database update:

' Processing for the database update

Private Sub cmdDML_Click(Index As Integer)

Dim iCount As Integer

Dim strSQL As String

Dim sMsg As String

Dim myUpdate As ADODB.Connection

Select Case Index

Case 0

strSQL = "UPDATE EMPLOYEE SET EMPLOYEE_ID='" & txtEmployee(0).Text & "', LAST_NAME='" & txtEmployee(1).Text & "', FIRST_NAME='" & txtEmployee(2).Text & "', EMAIL='" & txtEmployee(3) & "', CURRENT_SALARY='" & txtEmployee(4).Text & "' WHERE EMPLOYEE_ID='" & txtEmployee(0).Text & "'"

myADO.doUpdate (strSQL)

sMsg = "Record Updated"

MsgBox sMsg

Case 1

For iCount = 0 To 4

txtEmployee(iCount) = vbNullString

txtEmployee(iCount).DataChanged = False

Next iCount

SetFormState (fsAddNew)

txtEmployee(0).Enabled = False

txtEmployee(1).SetFocus

End Select

SubExit:

SetFormUI

Exit Sub

Page 43: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

End Sub

9. Now save the project and run

10. Enter the last name “libowitts” in the ‘sounds like’ TextBox and click Find

11. Change a salary and click save for the database update

Tutorial 3

For this tutorial we will create a new form, modeling a parent-child relationship using a data grid for the child rows. We will walk through the process of creating the queries to populate the parent, and then retrieve the associated child records. We will add code to step through multiple parent records moving forward and backward through dataset, and moving through child records. We will use the Invoice and Invoice_Item tables of the SQLBase Island database. For this tutorial, we will use OLE Db as our connectivity method.

1. Start Visual Basic 2. Create a new Standard EXE

Page 44: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

3. Add the included Module from \Module\FuncAdo.bas to the project 4. Add the included Module \Module\modDataIntoGrid.bas

Page 45: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

5. Add the included Class Module from \Class\ado.cls to the project

Page 46: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

6. Add the form frmLOGON.frm from \Tut2\frmLOGON.frm to the project 7. Save the form as \Tut3\frmLogon3.frm 8. Save the Module \Module\FuncAdo.cls as \Module\FuncAdo3.cls 9. Add the line indicated in red to the code

Option Explicit Public myADO As New adoGupta Public myADO1 As New adoGupta Public Sub main() Load frmLOGON frmLOGON.Show (vbModal) If myADO.logonState = True Then frmSearch.Show (vbModal) Else Call MsgBox("Logon Failed", vbInformation + vbOKOnly, "ADO Demo Application") End If End Sub

10. Now change the Sub cmdOK_Click() in the form frmLOGON to comment the

line indicated in orange and include the line indicated in red

Page 47: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Private Sub cmdOK_Click() ' Set the user and pwd properties myADO.user = txtUserName myADO.pwd = txtPassword ' Pass in the default Data Source Name 'myADO.dsn = "DSN=SQLBase Island Database" myADO.dsn = "Provider=SQLBASEOLEDB.1;Persist Security Info=False" ' Call the connect method Call myADO.connect ' Connection for the child records myADO1.user = txtUserName myADO1.pwd = txtPassword myADO1.dsn = "Provider=SQLBASEOLEDB.1;Persist Security Info=False" ' Call the connect method Call myADO1.connect ' Unload the form Unload Me End Sub

11. Next we need to design a form that looks like the following:

Page 48: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Object Name Form frmSearch TextBoxes txtCustomer (all 8) Query Command Buttons cmdFind

cmdClearFields Close Command Button cmdClose Navigation Command Buttons cmdNavigate (all 4) Label LblStatus Grid MSFlexGrid1

12. Add the following code to the form:

Option Explicit Private iFormState As Integer ' Constants to determine the state of the form Const fsNone = 0

Page 49: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Const fsEdited = 1 Const fsFound = 3 Const fsAddNew = 5 ' Function to process errors Private Function ProcessErrors(ErrorAt As String) Dim er As ADODB.Error Dim sMsg As String sMsg = "A serious error occurred in the " & ErrorAt & " Module. " & vbCrLf sMsg = sMsg & Err.Description MsgBox sMsg If myADO.getErrorCount > 0 Then sMsg = "Additional errors occurred in the " & ErrorAt & " Module. " & vbCrLf For Each er In myADO.getErrors sMsg = sMsg & " " & er & vbCrLf Next MsgBox sMsg End If End Function 'Sets the form's state Private Sub SetFormState(state As Integer) iFormState = state End Sub 'Sets the Status label and disables/enables buttons appropriately Public Sub SetFormUI() Dim iCount As Integer Select Case iFormState Case 0 ' Start Fresh after form start-up or clear For iCount = 0 To 3 cmdNavigate(iCount).Enabled = False Next iCount cmdFind.Enabled = True cmdClearFields.Enabled = False LblStatus.Caption = "Search for existing company" Case 1 'Edit For iCount = 0 To 3 cmdNavigate(iCount).Enabled = False Next iCount cmdFind.Enabled = True cmdClearFields.Enabled = True LblStatus.Caption = "Enter criteria for Search" Case 2 'Unknown

Page 50: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Case 3 'Found For iCount = 0 To 3 cmdNavigate(iCount).Enabled = True Next iCount cmdFind.Enabled = False cmdClearFields.Enabled = True LblStatus.Caption = "" Case 4 'Edit, Found For iCount = 0 To 3 cmdNavigate(iCount).Enabled = False Next iCount cmdFind.Enabled = False cmdClearFields.Enabled = True LblStatus.Caption = "Editing current company " Case Else 'Don’t have a clue End Select End Sub ' The SQL Select statement for Invoice records for customers Function BldCustQuery() As String Dim strSQL As String BldCustQuery = "SELECT COMPANY_ID, COMPANY_NAME, STATUS, EMPLOYEE_ID, INVOICE_NO, INVOICE_DATE, DATE_PAID, AMOUNT_PAID FROM INVOICE" BldCustQuery = BldCustQuery & bldWhere End Function ' Creates the Invoice Recordset for customers Function CreateCustomerSet(strSQL As String) As Boolean Dim myRS As ADODB.Recordset Dim iCount As Integer On Error GoTo CheckError myADO.setCursorType (adOpenKeyset) myADO.setLockType (adLockOptimistic) myADO.doSelect (strSQL) Set myRS = myADO.getRS If Not myRS.BOF And Not myRS.EOF Then myRS.MoveFirst End If FunctionExit: Exit Function

Page 51: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

CheckError: ProcessErrors ("Record Set Creation ") Resume Next Resume FunctionExit End Function ' The SQL Select statement for Invoice_Items Records Function BldInvQuery() As String Dim strSQL As String BldInvQuery = "SELECT INVOICE_NO, ITEM_NO, STYLE_ID, STYLE, COLOR, QUANTITY, ITEM_PRICE From INVOICE_ITEM" BldInvQuery = BldInvQuery & " WHERE INVOICE_NO = " & txtCustomer(4).Text End Function ' Creates the Invoice Details Recordset Function CreateInvoiceSet(strSQL As String) As Boolean Dim myInvRS As ADODB.Recordset Dim iCount As Integer On Error GoTo CheckError myADO1.setCursorType (adOpenKeyset) myADO1.setLockType (adLockOptimistic) myADO1.doSelect (strSQL) Set myInvRS = myADO1.getRS FunctionExit: Exit Function CheckError: ProcessErrors ("Record Set Creation ") Resume Next Resume FunctionExit End Function ' Sets Customer connection state Function SetCustCon() As Boolean On Error GoTo CheckError SetCustCon = True FunctionExit: Exit Function CheckError: ProcessErrors ("DB Connection ") Resume FunctionExit End Function

Page 52: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

' Build the where clause for any TextBox Function bldWhere() As String Dim iCount As Integer For iCount = 0 To 4 If txtCustomer(iCount) <> vbNullString Then If bldWhere <> vbNullString Then bldWhere = bldWhere & " and " End If bldWhere = bldWhere & txtCustomer(iCount).DataField & " = '" & txtCustomer(iCount).Text & "'" End If Next iCount If bldWhere <> vbNullString Then bldWhere = " Where " & bldWhere End If End Function ' Populates the TextBoxes Public Sub ShowRecord() Dim myRS As ADODB.Recordset Dim icol As Integer Dim iCount As Integer Set myRS = myADO.getRS For icol = 0 To 7 txtCustomer(icol) = myRS(icol) txtCustomer(icol).DataChanged = False Next icol SetFormState (fsFound) End Sub 'Populates the grid Public Sub ShowInvoice() Dim myInvRS As ADODB.Recordset Dim icol As Integer Dim iCount As Integer Set myInvRS = myADO1.getRS LoadRecordsetIntoGrid myInvRS, MSFlexGrid1, 1, 1 SetFormState (fsFound) End Sub ' Close the form when menu item clicked

Page 53: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Private Sub Close_Click() Unload Me End Sub ' Clear all TextBoxes Private Sub cmdClearFields_Click() Dim icol As Integer For icol = 0 To 7 txtCustomer(icol) = vbNullString Next icol MSFlexGrid1.Clear SetFormState (fsNone) SetFormUI End Sub ' Close the form when command button clicked Private Sub cmdClose_Click() Unload Me End Sub ' Processing for the Find button Private Sub cmdFind_Click() Dim myRS As ADODB.Recordset Dim strSQLSelect As String Set myRS = myADO.getRS strSQLSelect = BldCustQuery CreateCustomerSet (strSQLSelect) If myRS.EOF Or myRS.BOF Then MsgBox "No rows found matching your query..." Else SetFormState (fsFound) SetFormUI ShowRecord End If strSQLSelect = BldInvQuery CreateInvoiceSet (strSQLSelect) If myRS.EOF Or myRS.BOF Then MsgBox "No rows found matching your query..." Else SetFormState (fsFound) SetFormUI ShowInvoice End If End Sub

Page 54: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

' Processing for the Navigation buttons Private Sub cmdNavigate_Click(Index As Integer) Dim myRS As ADODB.Recordset Dim strAnswer As String Dim strSQLSelect As String Set myRS = myADO.getRS Select Case Index Case 0 myRS.MoveFirst Case 1 myRS.MovePrevious If myRS.BOF Then Beep myRS.MoveFirst End If Case 2 myRS.MoveNext If myRS.EOF Then Beep myRS.MoveLast End If Case 3 myRS.MoveLast End Select ShowRecord strSQLSelect = BldInvQuery CreateInvoiceSet (strSQLSelect) ShowInvoice End Sub ' Form load processing Private Sub Form_Load() Call SetCustCon Call SetFormState(fsNone) SetFormUI Screen.MousePointer = vbDefault End Sub ' Sets the form state on edit Private Sub txtCustomer_KeyPress(Index As Integer, KeyAscii As Integer) Select Case iFormState Case 0, 3, 5 If iFormState = 3 Then SetFormState (fsEdited + fsFound) ElseIf iFormState = 5 Then SetFormState (fsEdited + fsAddNew) Else SetFormState (fsEdited)

Page 55: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

End If SetFormUI End Select End Sub

13. Save the project, run and navigate through the Invoices and Invoice Details

Tutorial 4

Using the form created in Tutorial 3, this Tutorial adds code to allow updates to child records; restricting updates on primary keys. This Tutorial also demonstrates drop-down column abilities and editable MSFlexGrid columns

1. Start Visual Basic

2. Open the project \Tut3\VB_Tut3.vbp and save as \Tut4\VB_tut4.vbp

3. Save \Tut3\frmLOGON3.frm as \Tut4\frmLOGON4.frm

4. Save \Tut4\frmSEARCH3.frm as \Tut4\frmSEARCH4.frm

5. Save the Module \Module\FuncAdo3.bas as \Module\FuncAdo4.bas

6. Now add the object as indicated

Page 56: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Object Name Visible Label CellIndicator False ComboBox Combo1 False TextBox Text1 False Save Command Button cmdDML True

7. Edit the form code to add the lines indicated in red

Option Explicit

Private iFormState As Integer

' Constants to determine the state of the form

Const fsNone = 0

Const fsEdited = 1

Const fsFound = 3

Const fsAddNew = 5

Dim firstrow, firstcol As Integer

8. Edit the form code to add the lines indicated in red

Public Sub SetFormUI() Dim iCount As Integer Select Case iFormState Case 0 ' Start Fresh after form start-up or clear For iCount = 0 To 3 cmdNavigate(iCount).Enabled = False Next iCount cmdFind.Enabled = True cmdClearFields.Enabled = False cmdDML(0).Enabled = False LblStatus.Caption = "Search for existing company" Case 1 'Edit For iCount = 0 To 3 cmdNavigate(iCount).Enabled = False Next iCount cmdFind.Enabled = True cmdClearFields.Enabled = True cmdDML(0).Enabled = False LblStatus.Caption = "Enter criteria for Search" Case 2 'Unknown Case 3 'Found For iCount = 0 To 3 cmdNavigate(iCount).Enabled = True

Page 57: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Next iCount cmdFind.Enabled = False cmdDML(0).Enabled = False cmdClearFields.Enabled = True LblStatus.Caption = "" Case 4 'Edit, Found For iCount = 0 To 3 cmdNavigate(iCount).Enabled = False Next iCount cmdFind.Enabled = False cmdDML(0).Enabled = True cmdClearFields.Enabled = True LblStatus.Caption = "Editing current company " Case Else 'Don’t have a clue End Select End Sub

9. Add the following code to the form ' Processing for the child table update Private Sub cmdDML_Click(Index As Integer) Dim iCount As Integer Dim strSQL, strData As String Dim myUpdate As ADODB.Connection Dim intRow, intCol As Integer Dim rowData() As Variant iCount = 1 ReDim rowData(MSFlexGrid1.Cols - 1) For intRow = 1 To MSFlexGrid1.Rows - 1 For intCol = iCount To MSFlexGrid1.Cols - 1 MSFlexGrid1.Col = intCol MSFlexGrid1.Row = intRow rowData(intCol) = MSFlexGrid1.Text Next intCol strSQL = "UPDATE INVOICE_ITEM SET INVOICE_NO='" & rowData(2) & "', ITEM_NO='" & rowData(3) & "', STYLE_ID='" & rowData(4) & "', STYLE='" & rowData(5) & "', COLOR='" & rowData(6) & "', QUANTITY='" & rowData(7) & "', ITEM_PRICE='" & rowData(8) & "' WHERE ROWID='" & rowData(1) & "'" myADO1.doUpdate (strSQL) Next intRow SubExit: SetFormUI Exit Sub

Page 58: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

End Sub ' Processing for form resize Private Sub Form_Resize() Text1.Left = MSFlexGrid1.CellLeft + MSFlexGrid1.Left Text1.Top = MSFlexGrid1.CellTop Text1.Height = MSFlexGrid1.CellHeight Text1.Width = MSFlexGrid1.CellWidth Combo1.Left = MSFlexGrid1.CellLeft + MSFlexGrid1.Left Combo1.Top = MSFlexGrid1.CellTop Combo1.Width = MSFlexGrid1.CellWidth End Sub

10. Replace the Form_Load Sub with the following: Private Sub Form_Load() Call SetCustCon Call SetFormState(fsNone) SetFormUI Screen.MousePointer = vbDefault Text1.Visible = False MSFlexGrid1.FixedCols = 0 Dim y% With MSFlexGrid1 .ColAlignment(-1) = 1 For y% = 1 To .Cols - 1 .TextMatrix(0, y%) = "Col " + Str(y%) Next For y% = 1 To MSFlexGrid1.Rows - 1 .TextMatrix(y%, 0) = "Row " + Str(y%) Next .Row = 1 .Col = 1 .CellBackColor = &HC0FFFF 'lt. yellow frmSearch.CellIndicator = " " + .TextMatrix(.Row, 0) + " : " + .TextMatrix(0, .Col) + " " End With Combo1.ZOrder (0) Combo1.Width = MSFlexGrid1.CellWidth ' Load the ComboBox's list. Combo1.AddItem "Black" Combo1.AddItem "Blue" Combo1.AddItem "Red"

Page 59: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Combo1.AddItem "Green" Combo1.AddItem "Yellow" End Sub

11. Add the following to the code: ' Change color of TextBox when cell is entered

Private Sub MSFlexGrid1_EnterCell()

frmSearch.CellIndicator = " " + MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 0) + " : " + MSFlexGrid1.TextMatrix(0, MSFlexGrid1.Col) + " "

Text1.Visible = False

MSFlexGrid1.Tag = MSFlexGrid1

MSFlexGrid1.CellBackColor = &HC0FFFF 'lt. yellow

End Sub

' Change color of TextBox when cell is left

Private Sub MSFlexGrid1_LeaveCell()

MSFlexGrid1.CellBackColor = &H80000005 'white

End Sub

' Setup TextBox for editing when keydown

Private Sub MSFlexGrid1_KeyDown(KeyCode As Integer, Shift As Integer)

Select Case KeyCode

Case 113 'F2

Set_TextBox

End Select

End Sub

' Setup TextBox for editing when keypress

Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)

MSFlexGrid1 = Chr$(KeyAscii)

Text1 = Chr$(KeyAscii)

Set_TextBox

Select Case iFormState

Case 0, 3, 5

If iFormState = 3 Then

SetFormState (fsEdited + fsFound)

Page 60: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

ElseIf iFormState = 5 Then

SetFormState (fsEdited + fsAddNew)

Else

SetFormState (fsEdited)

End If

SetFormUI

End Select

End Sub

' Setup TextBox for editing when keydown in TextBox

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)

Select Case KeyCode

Case 27 'ESC - OOPS, restore old text

Text1 = MSFlexGrid1.Tag

Text1.SelStart = Len(Text1)

Case 37 'Left Arrow

If Text1.SelStart = 0 And MSFlexGrid1.Col > 1 Then

MSFlexGrid1.Col = MSFlexGrid1.Col - 1

Else

If Text1.SelStart = 0 And MSFlexGrid1.Row > 1 Then

MSFlexGrid1.Row = MSFlexGrid1.Row - 1

MSFlexGrid1.Col = MSFlexGrid1.Cols - 1

End If

End If

Case 38 'Up Arrow

If MSFlexGrid1.Row > 1 Then

MSFlexGrid1.Row = MSFlexGrid1.Row - 1

End If

Case 39 'Rt Arrow

If Text1.SelStart = Len(Text1) And MSFlexGrid1.Col < MSFlexGrid1.Cols - 1 Then

MSFlexGrid1.Col = MSFlexGrid1.Col + 1

Else

If Text1.SelStart = Len(Text1) And MSFlexGrid1.Row < MSFlexGrid1.Rows - 1 Then

MSFlexGrid1.Row = MSFlexGrid1.Row + 1

Page 61: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

MSFlexGrid1.Col = 1

End If

End If

Case 40 'Dn Arrow

If MSFlexGrid1.Row < MSFlexGrid1.Rows - 1 Then

MSFlexGrid1.Row = MSFlexGrid1.Row + 1

End If

End Select

IsCellVisible

End Sub

' Setup TextBox for editing when mousedown on grid

Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)

Dim Row%, Col%

Text1.Visible = False

Row% = MSFlexGrid1.MouseRow

Col% = MSFlexGrid1.MouseCol

If Button = 2 And (Col% = 0 Or Row% = 0) Then

MSFlexGrid1.Col = IIf(Col% = 0, 1, Col%) 'rows?

MSFlexGrid1.Row = IIf(Row% = 0, 1, Row%) 'or cols?

End If

If MSFlexGrid1.Col = 6 Then

Set_ComboBox

End If

Select Case iFormState

Case 0, 3, 5

If iFormState = 3 Then

SetFormState (fsEdited + fsFound)

ElseIf iFormState = 5 Then

SetFormState (fsEdited + fsAddNew)

Else

SetFormState (fsEdited)

End If

Page 62: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

SetFormUI

End Select

End Sub

' Setup TextBox to overlay grid

Private Sub Set_TextBox() 'put textbox over cell

With Text1

.Top = MSFlexGrid1.Top + MSFlexGrid1.CellTop

.Left = MSFlexGrid1.Left + MSFlexGrid1.CellLeft

.Width = MSFlexGrid1.CellWidth

.Height = MSFlexGrid1.CellHeight

.Text = MSFlexGrid1

.Visible = True

.SelStart = Len(.Text)

.SetFocus

End With

End Sub

' Setup ComboBox to overlay grid

Private Sub Set_ComboBox() 'put combobox over cell

Combo1.Width = MSFlexGrid1.CellWidth

Combo1.Left = MSFlexGrid1.CellLeft + MSFlexGrid1.Left

Combo1.Top = MSFlexGrid1.CellTop + MSFlexGrid1.Top

Combo1.Text = MSFlexGrid1.Text

Combo1.Visible = True

End Sub

' Copy contents of ComboBox to grid

Private Sub Combo1_Click()

' Place the selected item into the Cell and hide the ComboBox.

MSFlexGrid1.Text = Combo1.Text

Combo1.Visible = False

End Sub

12. Now save the project and run

Page 63: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

13. Click on Find, edit the Color (choose a different color) in the grid, Click on Save

Tutorial 5 This Tutorial demonstrates the ability to retrieve and save graphics to SQLBase.

1. Start Visual Basic 2. Create a new Standard EXE

Page 64: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

3. Add the included Module from \Module\FuncAdo5.bas to the project 4. Add the included Module from \Class\ado5.bas to the project 5. Add the included Form from \Tut4\frmLOGON4.frm to the project and save as

\Tut5\frmLOGON5.frm 6. Add the included Form from \Tut1\frmSEARCH.frm and save as

\Tut5\frmSEARCH5.frm 7. Save the Project as \Tut5\VB_Tut5 8. Modify the form design to include the objects indicated:

Page 65: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Object Name Image Image1 CommonDialog dlgDialog Save Command Button cmdSelectSave

9. Add the line indicated in red to the form’s code

Option Explicit Private iFormState As Integer Const fsNone = 0 Const fsEdited = 1 Const fsFound = 3 Const fsAddNew = 5 Dim strStream As ADODB.Stream

10. Add the line indicated in red to the ShowRecord Sub

Public Sub ShowRecord()

Dim myRS As ADODB.Recordset

Dim icol As Integer

Dim iCount As Integer

Page 66: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Set myRS = myADO.getRS

For icol = 0 To 4

txtCustomer(icol) = myRS(icol)

txtCustomer(icol).DataChanged = False

Next icol

If Not LoadPictureFromDB(myRS) Then

MsgBox "Invalid Data Or No Picture In DB"

End If

SetFormState (fsFound)

End Sub

11. Add the line indicated in red to the ShowRecord Sub

Private Sub cmdClearFields_Click()

Dim iCount As Integer

For iCount = 0 To 4

txtCustomer(iCount) = vbNullString

txtCustomer(iCount).DataChanged = False

Next iCount

Image1.Picture = Nothing

txtCustomer(0).Enabled = True

SetFormState (fsNone)

SetFormUI

End Sub

12. Add the following code to the form’s code

Private Sub cmdDML_Click(Index As Integer) Dim iCount As Integer Dim strSQL As String Dim myUpdate As ADODB.Connection Select Case Index Case 0 strSQL = "UPDATE EMPLOYEE SET EMPLOYEE_ID='" & txtCustomer(0).Text & "', LAST_NAME='" & txtCustomer(1).Text & "', FIRST_NAME='" & txtCustomer(2).Text & "', EMAIL='" & txtCustomer(3) & "',

Page 67: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

CURRENT_SALARY='" & txtCustomer(4).Text & "' WHERE EMPLOYEE_ID='" & txtCustomer(0).Text & "'" myADO.doUpdate (strSQL) Case 1 For iCount = 0 To 4 txtCustomer(iCount) = vbNullString txtCustomer(iCount).DataChanged = False Next iCount SetFormState (fsAddNew) txtCustomer(0).Enabled = False txtCustomer(1).SetFocus End Select SubExit: SetFormUI Exit Sub End Sub Private Sub cmdSelectSave_Click() 'Open Dialog Box Dim myRS As ADODB.Recordset Set myRS = myADO.getRS With dlgDialog .DialogTitle = "Open Image File...." .Filter = "Image Files (*.gif; *.bmp)| *.gif;*.bmp" .CancelError = True procReOpen: .CancelError = True .ShowOpen If .FileName = "" Then MsgBox "Invalid filename or file not found.", _ vbOKOnly + vbExclamation, "Oops!" GoTo procReOpen Else If Not SavePictureToDB(myRS, .FileName) Then MsgBox "Save was unsuccessful :(", vbOKOnly + _ vbExclamation, "Oops!" Exit Sub End If End If End With End Sub Public Function LoadPictureFromDB(RS As ADODB.Recordset)

Page 68: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

On Error GoTo procNoPicture 'If Recordset is Empty, Then Exit If RS Is Nothing Then GoTo procNoPicture End If Dim chunk() As Byte chunk() = StrConv(RS("PHOTO").Value, vbFromUnicode) Set strStream = New ADODB.Stream strStream.Type = adTypeBinary strStream.Open strStream.Write chunk strStream.SaveToFile "C:\Temp.gif", adSaveCreateOverWrite Image1.Picture = LoadPicture("C:\Temp.gif") Kill ("C:\Temp.gif") LoadPictureFromDB = True procExitFunction: Exit Function procNoPicture: LoadPictureFromDB = False GoTo procExitFunction End Function Public Function SavePictureToDB(RS As ADODB.Recordset, _ sFileName As String) On Error GoTo procNoPicture Dim oPict As StdPicture Set oPict = LoadPicture(sFileName) 'Exit Function if this is NOT a picture file If oPict Is Nothing Then MsgBox "Invalid Picture File!", vbOKOnly, "Oops!" SavePictureToDB = False GoTo procExitSub End If Set strStream = New ADODB.Stream strStream.Type = adTypeBinary strStream.Open strStream.LoadFromFile sFileName strStream.Position = 0

Page 69: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

strStream.Type = adTypeText strStream.Charset = "ISO-8859-1" RS.Fields("PHOTO").Value = strStream.ReadText RS.Save Image1.Picture = LoadPicture(sFileName) SavePictureToDB = True procExitSub: Exit Function procNoPicture: SavePictureToDB = False GoTo procExitSub End Function

13. Now save the project and run

14. Click on Find and navigate through the resultset to view the images from the databases

15. Click on Save

16. This opens a Dialog to select a new image. Select an image and click open

17. Now navigate the resultset to see the new image inserted

Page 70: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Page 71: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Visual Basic .NET Tutorials

Tutorial 1 This tutorial will walk you through creating code for connecting to the SQLBase Island database using the .NET Provider for SQLBase. We will then create a simple single table form, populating TextBoxes. We will include code that allows you to step forward and backward through data, go to the last record and go to first record.

1. Start Visual Studio .NET 2. Create a new Windows Application Visual Basic Project

3. Next we need to add a reference to the SQLBase .NET Provider

Page 72: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

4. Find Gupta SQLBase .Net Data Provider, Click Select and then OK.

Page 73: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

5. Now resize the Form and place the following controls on it from the Toolbox

Page 74: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Object Name Form frmSearch TextBoxes txtEmployeeID

txtLastName txtFirstName txtEmail txtSalary

Query Command Buttons cmdFind cmdClearFields

Close Command Button cmdClose Navigation Command Buttons cmdNavigate0

cmdNavigate1 cmdNavigate2 cmdNavigate3

Label lblNavigate

6. Now right-click on the form frmSearch and select View Code to see the following

7. Create a line above the first line and include the Namespace as indicated

Page 75: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

8. Next, declare the global variables

9. Add the Public Sub CreateDataBindings() to bind the TextBoxes with the database table columns to assist with the result set navigation

Page 76: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

10. Next, we add code to handle the click event of the Find button.

11. Add code to handle the Click event of the Navigation buttons

12. Add code to handle the click event of the Clear button

Page 77: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

13. Finally, handle the Click event of the Close button

14. Now Save the project and hit F5 to run the application

15. Click the Find button, then navigate the DataSet with the Navigation buttons

Page 78: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Tutorial 2

This Tutorial expands on Tutorial 1, allowing one to query by placing a partial name in a field and using the soundex() function to retrieve data. This Tutorial also shows you how to update and save data to the database.

1. Start Visual Basic .NET 2. Create the directory \SQLBase 9.0\Tutorials\Visual Basic .NET\Tut2\ 3. Copy the files VBNET_Tut1.vbproj, frmSearch.vb, frmsearch.resx &

AssemblyInfo.vb to the new directory 4. Open the Project \SQLBase 9.0\Tutorials\Visual Basic

.NET\Tut2\VBNET_Tut2.vbproj 5. Rename the solution VBNET_Tut1 to VBNET_Tut2, the project

VBNET_Tut1 to VBNET_Tut2 and the form frmSearch to frmSearch2

6. Right-click the project VBNET_Tut2 and select properties 7. Change the Assembly name and Root namespace from VBNET_Tut1 to

VBNET_Tut2, and select frmSearch2 as the Startup object and click OK

Page 79: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

8. Now right-click on frmSearch2.vb and select View Designer 9. Now resize the form frmSearch to add a Label and TextBox and the Save

button as illustrated:

Object Name TextBox txtSearch

Page 80: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Save Command Button cmdSave

10. Right-click on the form and select View Code

11. Now declare the global variables for this tutorial

12. Concatenate the select statement with the sWhere variable, making sure there is a space after the table name EMPLOYEE, as illustrated:

13. Add the code to setup the where clause

Page 81: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

14. Add the bind parameter and set its value

15. Edit the cmdClearFields Click event to add code to clear the sounds like TextBox

Page 82: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

16. Now add the code for the database update

17. Save the project, hit F5 to run

18. Enter the last name “libowitts”, and click Find

Page 83: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

19. Change the salary to 53,000 and click Save

20. If successful, you should see the following screen

Page 84: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Tutorial 3

For this tutorial we will create a new form, modeling a parent-child relationship using a data grid for the child rows. We will walk through the process of creating the queries to populate the parent, and then retrieve the associated child records. We will add code to step through multiple parent records moving forward and backward through dataset, and moving through child records. We will use the Invoice and Invoice_Item tables of the SQLBase Island database.

1. Start Visual Studio .NET 2. Create a new Windows Application Visual Basic Project

3. Next we need to add a reference to the SQLBase .NET Provider

Page 85: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

4. Find Gupta SQLBase .Net Data Provider, Click Select and then OK.

Page 86: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

5. Now resize the Form and place the following controls on it from the Toolbox

Page 87: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Object Name Form frmSearch TextBoxes txtCompanyID

txtCompanyName txtStatus txtEmployeeID txtInvoiceNo txtInvoiceDate txtDatePaid txtDatePaid

Query Command Buttons cmdFind cmdClearFields

Close Command Button cmdClose Navigation Command Buttons cmdNavigate0

cmdNavigate1 cmdNavigate2 cmdNavigate3

Label lblNavigate DataGrid DataGrid1

6. Now right-click on the form frmSearch and select View Code to see the following

Page 88: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

7. Create a line above the first line and include the Namespace as indicated

8. Next, declare the global variables

9. Bind the TextBoxes with the DataSet

Page 89: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

10. Create the function to build the parent table result set

11. Next we create the function to build the child table result set and bind it to the Data Grid

Page 90: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

12. Now we handle the click event of the Find button

13. Setup the navigation buttons

14. Handle the cmdClearFields click event

Page 91: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

15. Handle the click event of the Close button

16. Switch to Designer View, right-click on the Data Grid and select properties

17. Change the Visible property to False

18. Save the project and hit F5 to run

19. Click Find and navigate the result set

Page 92: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Tutorial 4

Using the form created in Tutorial 3, this Tutorial adds code to allow updates to child records; restricting updates on primary keys. This Tutorial also demonstrates drop-down column abilities and editable MSFlexGrid columns

1. Start Visual Basic .NET 2. Create the directory \SQLBase 9.0\Tutorials\Visual Basic .NET\Tut4\ 3. Copy the files VBNET_Tut3.vbproj, frmSearch.vb, frmsearch.resx &

AssemblyInfo.vb to the new directory 4. Open the Project \SQLBase 9.0\Tutorials\Visual Basic

.NET\Tut4\VBNET_Tut3.vbproj 5. Rename the solution VBNET_Tut3 to VBNET_Tut4 and the project

VBNET_Tut3 to VBNET_Tut4

Page 93: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

6. Right-click the project VBNET_Tut4 and select properties 7. Change the Assembly name and Root namespace from VBNET_Tut3 to

VBNET_Tut4, and click OK

8. Now right-click on frmSearch.vb and select View Designer 9. Now add the Save button, change the background color of the Textboxes and

set the enabled property for the button and TextBoxes to false:

Page 94: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Object Name Save Command Button cmdSave

10. Right-click on the form and select View Code

11. Declare the variables for this Tutorial and a Combobox, as follows:

12. Add a new subroutine to setup the Combobox and DataGrid

Page 95: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

13. Add the following subs for the DataGrid and Combox merge

Page 96: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

14. Declare the variable BldUpdCmd in the function CreateInvoiceSet

15. Then add the following for the DataGrid update and bind parameters:

16. Add code for FillSchema for the Adapter update and comment out the close connect line at the end of the function

Page 97: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

17. Add the highlighted line to the CreateCustomerSet function

18. Add the highlighted line to the cmdClearFields_Click event

Page 98: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

19. Handle the click event for the Save button

20. Save the project, and hit F5 to run 21. Click Find, navigate the master-detail records 22. Edit a color column in the DataGrid to change a color, and click Save

Page 99: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

23. If successful, the following will appear:

Tutorial 5 This Tutorial demonstrates the ability to retrieve and save graphics to SQLBase.

1. Start Visual Basic .NET 2. Create the directory \SQLBase 9.0\Tutorials\Visual Basic .NET\Tut5\ 3. Copy the files VBNET_Tut1.vbproj, frmSearch.vb, frmSearch.resx &

AssemblyInfo.vb to the new directory 4. Open the Project \SQLBase 9.0\Tutorials\Visual Basic

.NET\Tut5\VBNET_Tut1.vbproj 5. Rename the solution VBNET_Tut1 to VBNET_Tut5, the project

VBNET_Tut1 to VBNET_Tut5

Page 100: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

6. Right-click the project VBNET_Tut5 and select properties 7. Change the Assembly name and Root namespace from VBNET_Tut1 to

VBNET_Tut5, and select frmSearch2 as the Startup object and click OK

Page 101: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

8. Now right-click on frmSearch.vb and select View Designer 9. Add a PictureBox object and the Save button as illustrated:

Object Name PictureBox photo Save Command Button cmdSave

10. Change the Visible property of the PictureBox to False

11. Select Tools and Customize Toolbox

Page 102: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

12. Select the Microsoft Common Dialog Control and click OK

13. Now select this control from the Toolbox

Page 103: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

14. Drop and instance on the form

Page 104: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Object Name CommonDialog dlgDialog

15. Right-click on the form and select View Code

16. Add the namespace for IO operations

17. Add the function to display the photo

Page 105: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

18. Add the highlighted lines to the Sub CreateDataBindings

19. Add the column PHOTO to the select list

Page 106: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

20. Call the ShowPhoto() function from each of the navigation button’s event

21. Add the highlighted line to the cmdClearFields event

22. Handle the Save button click event

Page 107: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

23. Add the function to save the image to the database

24. Save the project, and hit F5 to run

25. Click on Find, and scroll the result set

26. Now click on Save to open the following dialog

Page 108: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

27. Select a gif or bmp and lick Open

28. You should receive a message box stating that the Image was updated

29. Click on Clear and then Find

30. Scroll through the result set to view the update

C# Tutorials

Tutorial 1

This tutorial will walk you through creating code for connecting to the SQLBase Island database using the .NET Provider for SQLBase. We will then create a simple single table form, populating TextBoxes. We will include code that allows you to step forward and backward through data, go to the last record and go to first record.

1. Start Visual Studio .NET 2. Create a new Windows Application C# Project

Page 109: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

3. Next we need to add a reference to the SQLBase .NET Provider

4. Find Gupta SQLBase .Net Data Provider, Click Select and then OK.

Page 110: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

5. Rename Form1.cs to frmSearch.cs in the Solution Explorer

Page 111: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

6. Right-click on frmSearch.cs and select View Designer

7. Now resize the Form and place the following controls on it from the Toolbox

Page 112: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Object Name Form frmSearch TextBoxes txtEmployeeID

txtLastName txtFirstName txtEmail txtSalary

Query Command Buttons cmdFind cmdClearFields

Close Command Button cmdClose Navigation Command Buttons cmdNavigate0

cmdNavigate1 cmdNavigate2 cmdNavigate3

Label lblNavigate GroupBox GBQuery

8. Now right-click on the form frmSearch and select View Code to see the following:

Page 113: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

9. Add the Namespace for the SQLBase .NET Provider, as indicated

10. Next, replace all occurrences of name Form1 with frmSearch

11. Declare the global variables

Page 114: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

12. Add the Function CreateDataBindings() to bind the TextBoxes with the database table columns to assist with the result set navigation

Page 115: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

13. Next, we add code to handle the click event of the Find button.

14. Add code to handle the Click event of the Navigation buttons

15. Add code to handle the click event of the Clear button

Page 116: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

16. Finally, handle the Click event of the Close button

17. Now Save the project and hit F5 to run the application

18. Click the Find button, then navigate the DataSet with the Navigation buttons

Page 117: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Tutorial 2

This Tutorial expands on Tutorial 1, allowing one to query by placing a partial name in a field and using the soundex() function to retrieve data. This Tutorial also shows you how to update and save data to the database.

1. Start Visual Studio .NET 2. Create the directory \SQLBase 9.0\Tutorials\C#\Tut2\ 3. Copy the files CSharp_Tut1.csproj, frmSearch.cs, frmSearch.resx &

AssemblyInfo.cs to the new directory 4. Open the Project \SQLBase 9.0\Tutorials\C#\Tut2\ CSharp_Tut1.csproj 5. Rename the solution CSharp_Tut1 to CSharp_Tut2, the project

CSharp_Tut1 to CSharp_Tut2 and the form frmSearch to frmSearch2

6. Right-click the project VBNET_Tut2 and select properties 7. Change the Assembly Name and Default Namespace from CSharp_Tut1 to

CSharp_Tut2 and click OK

Page 118: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

8. Now right-click on frmSearch2.cs and select View Designer 9. Now resize the form frmSearch2 to add a Label and TextBox and the Save

button as illustrated:

Object Name

Page 119: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

TextBox txtSearch Save Command Button cmdSave

10. Right-click on the form and select View Code

11. Now declare the global variables for this tutorial

12. Concatenate the select statement with the sWhere variable, making sure there is a space after the table name EMPLOYEE, as illustrated:

13. Add the code to setup the where clause

Page 120: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

14. Add the bind parameter and set its value

15. Edit the cmdClearFields Click event to add code to clear the sounds like TextBox

Page 121: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

16. Now add the code for the database update

17. Save the project, hit F5 to run

18. Enter the last name “libowitts”, and click Find

Page 122: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

19. Change the salary to 63,000 and click Save

20. If successful, you should see the following screen

Page 123: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Tutorial 3 This tutorial will walk you through creating code for connecting to the SQLBase Island database using the .NET Provider for SQLBase. We will then create a simple single table form, populating TextBoxes. We will include code that allows you to step forward and backward through data, go to the last record and go to first record.

1. Start Visual Studio .NET 2. Create a new Windows Application C# Project

3. Next we need to add a reference to the SQLBase .NET Provider

Page 124: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

4. Find Gupta SQLBase .Net Data Provider, Click Select and then OK.

Page 125: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

5. Rename Form1.cs to frmSearch.cs in the Solution Explorer

Page 126: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

6. Right-click on frmSearch.cs and select View Designer

7. Now resize the Form and place the following controls on it from the Toolbox

Page 127: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Object Name Form frmSearch TextBoxes txtCompanyID

txtCompanyName txtStatus txtEmployeeID txtInvoiceNo txtInvoiceDate txtDatePaid txtAmountPaid

Query Command Buttons cmdFind cmdClearFields

Close Command Button cmdClose Navigation Command Buttons cmdNavigate0

cmdNavigate1 cmdNavigate2 cmdNavigate3

Label lblNavigate DataGrid DataGrid1

8. Now right-click on the form frmSearch and select View Code to see the following

9. Include the SQLBase .NET Provider Namespace, as indicated:

Page 128: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

10. Next, declare the global variables

11. Add the Public Sub CreateDataBindings() to bind the TextBoxes with the database table columns to assist with the result set navigation

12. Create the function to build the parent table result set

Page 129: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

13. Add the function to handle the creation of the child table result set

14. Next, we add code to handle the click event of the Find button.

Page 130: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

15. Add code to handle the Click event of the Navigation buttons

16. Add code to handle the click event of the Clear button

Page 131: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

17. Finally, handle the Click event of the Close button

18. Now Save the project and hit F5 to run the application

19. Click the Find button, then navigate the DataSet with the Navigation buttons

Page 132: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Tutorial 4 Using the form created in Tutorial 3, this Tutorial adds code to allow updates to child records; restricting updates on primary keys. This Tutorial also demonstrates drop-down column abilities and editable DataGrid columns

1. Start Visual Studio .NET 2. Create the directory \SQLBase 9.0\Tutorials\C#\Tut4\ 21. Copy the files CSharp_Tut3.csproj, frmSearch.cs, frmSearch.resx, App.ico &

AssemblyInfo.cs to the new directory 22. Open the Project \SQLBase 9.0\Tutorials\C#\Tut4\ CSharp_Tut3.csproj 23. Rename the solution CSharp_Tut3 to CSharp_Tut4, and the project

CSharp_Tut3 to CSharp_Tut4

Page 133: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

3. Right-click the project VBNET_Tut4 and select properties 4. Change the Assembly Name and Default Namespace from CSharp_Tut3 to

CSharp_Tut4, and click OK

Page 134: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

5. Now right-click on frmSearch.vb and select View Designer 6. Now add the Save button, change the background color of the Textboxes and

set the enabled property for the button and TextBoxes to false:

Page 135: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Object Name Save Command Button cmdSave

7. Right-click on the form and select View Code

8. Rename the Namespace CSharp_Tut3 to CSharp_Tut5

9. Declare the variables for this Tutorial and a Combobox, as follows:

10. Add a new function to setup the Combobox and DataGrid

Page 136: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

11. Add the following functions for the DataGrid and ComboBox Events

Page 137: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Page 138: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

12. Declare the variable BldUpdCmd in the function CreateInvoiceSet

Page 139: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

13. Then add the following for the DataGrid update and bind parameters:

14. Add code for FillSchema for the Adapter update and comment out the close connect line at the end of the function

Page 140: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

15. Add the highlighted line to the CreateCustomerSet function

16. Add the highlighted line to the cmdClearFields_Click event

17. Handle the click event for the Save button

Page 141: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

18. Add the EventHandlers in the function InitializeComponent

19. Access the properties for the DataGrid to setup the events as shown

Page 142: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Page 143: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

20. Save the project, and hit F5 to run 21. Click Find, navigate the master-detail records 22. Edit a color column in the DataGrid to change a color, and click Save

Page 144: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

23. If successful, the following will appear:

Page 145: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Tutorial 5

This Tutorial demonstrates the ability to retrieve and save graphics to SQLBase.

1. Start Visual Studio .NET 2. Create the directory \SQLBase 9.0\Tutorials\C#\Tut5\ 3. Copy the files Csharp.csproj, frmSearch.cs, frmSearch.resx, App.ico &

AssemblyInfo.cs to the new directory 4. Open the Project \SQLBase 9.0\Tutorials\C#\Tut5\CSharp_Tut1.csproj 5. Rename the solution CSharp_Tut1 to CSharp_Tut5, the project

CSharp_Tut1 to CSharp_Tut5

6. Right-click the project CSharp_Tut5 and select properties 7. Change the Assembly Name and Default Namespace from CSharp_Tut1 to

CSharp_Tut5 and click OK

Page 146: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

8. Now right-click on frmSearch.cs and select View Designer 9. Add a PictureBox object and the Save button as illustrated:

Object Name PictureBox photo Save Command Button cmdSave

Page 147: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

10. Change the Visible property of the PictureBox to False

11. Right-click on the form and select View Code

12. Add the namespace for IO operations

13. Rename the CSharp_Tut1 namespace to CSharp_Tut5

14. Add the function to display the photo

15. Add the highlighted lines to the function CreateDataBindings

Page 148: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

16. Add the column PHOTO to the select list

17. Call the ShowPhoto() function from each of the navigation button’s event

Page 149: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

18. Add the highlighted line to the cmdClearFields event

19. Handle the Save button click event

Page 150: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

20. Add the function to save the image to the database

21. Save the project, and hit F5 to run

22. Click on Find, and scroll the result set

23. Now click on Save to open the following dialog

Page 151: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

24. Select a gif or bmp and Click Open

25. You should receive a message box stating that the Image was updated

26. Click on Clear and then Find

27. Scroll through the result set to view the update

Page 152: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Microsoft Visual J# .NET is a development tool that developers who are familiar with the Java-language syntax can use to build applications and services on the .NET Framework. It integrates the Java-language syntax into the Visual Studio .NET shell. Microsoft Visual J# .NET also supports the functionality found in Microsoft VJ++ 6.0 including Microsoft extensions. Microsoft Visual J# .NET is not a tool for developing applications intended to run on a Java Virtual Machine. Applications and services built with Visual J# .NET will run only on the .NET Framework.

J# Tutorials

Tutorial 1

This tutorial will walk you through creating code for connecting to the SQLBase Island database using the .NET Provider for SQLBase. We will then create a simple single table form, populating TextBoxes. We will include code that allows you to step forward and backward through data, go to the last record and go to first record.

1. Start Visual Studio .NET 2. Create a new Windows Application J# Project

3. Next we need to add a reference to the SQLBase .NET Provider

Page 153: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

4. Find Gupta SQLBase .Net Data Provider, Click Select and then OK.

Page 154: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

5. Rename Form1.jsl to frmSearch.jsl in the Solution Explorer

Page 155: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

6. Right-click on frmSearch.jsl and select View Designer

7. Now resize the Form and place the following controls on it from the Toolbox

Page 156: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Object Name Form frmSearch TextBoxes txtEmployeeID

txtLastName txtFirstName txtEmail txtSalary

Query Command Buttons cmdFind cmdClearFields

Close Command Button cmdClose Navigation Command Buttons cmdNavigate0

cmdNavigate1 cmdNavigate2 cmdNavigate3

Label lblNavigate GroupBox GBQuery

8. Now right-click on the form frmSearch and select View Code to see the following:

Page 157: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

9. Add the Namespace for the SQLBase .NET Provider, as indicated

10. Next, replace all occurrences of name Form1 with frmSearch

Page 158: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

11. Declare the global variables

Page 159: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

12. Add the Function CreateDataBindings() to bind the TextBoxes with the database table columns to assist with the result set navigation

Page 160: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

13. Next, we add code to handle the click event of the Find button.

14. Add code to handle the Click event of the Navigation buttons

Page 161: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

15. Add code to handle the click event of the Clear button

Page 162: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

16. Finally, handle the Click event of the Close button

17. Now Save the project and hit F5 to run the application

18. Click the Find button, then navigate the DataSet with the Navigation buttons

Page 163: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Tutorial 2 This Tutorial expands on Tutorial 1, allowing one to query by placing a partial name in a field and using the soundex() function to retrieve data. This Tutorial also shows you how to update and save data to the database.

1. Start Visual Studio .NET 2. Create the directory \SQLBase 9.0\Tutorials\J#\Tut2\ 3. Copy the files JSharp_Tut1.vjsproj, frmSearch.jsl, frmSearch.resx &

AssemblyInfo.jsl to the new directory 4. Open the Project \SQLBase 9.0\Tutorials\J#\Tut2\JSharp_Tut1.vjsproj 5. Rename the solution JSharp_Tut1 to JSharp_Tut2, the project

JSharp_Tut1 to JSharp_Tut2

Page 164: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

6. Right-click the project JSharp_Tut2 and select properties 7. Change the Assembly Name and Default Package from JSharp_Tut1 to

JSharp_Tut2 and click OK

Page 165: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

8. Now right-click on frmSearch.jsl and select View Designer 9. Now resize the form frmSearch to add a Label and TextBox and the Save

button as illustrated:

Object Name TextBox txtSearch

Page 166: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Save Command Button cmdSave

10. Right-click on the form and select View Code

11. Now declare the global variables for this tutorial

12. Concatenate the select statement with the sWhere variable, making sure there is a space after the table name EMPLOYEE, as illustrated

13. Setup the Adaptor’s select command, add the parameter, and set its value

14. Add the code to setup the where clause

Page 167: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

15. Edit the cmdClearFields Click event to add code to clear the sounds like TextBox

16. Now add the code for the database update

Page 168: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

17. Save the project, hit F5 to run

18. Enter the last name “libowitts”, and click Find

19. Change the salary to 63,000 and click Save

20. If successful, you should see the following screen

Page 169: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

21. Now clear the fields and Click Find to navigate to the record you just updated

Tutorial 3 This tutorial will walk you through creating code for connecting to the SQLBase Island database using the .NET Provider for SQLBase. We will then create a simple single table form, populating TextBoxes. We will include code that allows you to step forward and backward through data, go to the last record and go to first record.

1. Start Visual Studio .NET 2. Create a new Windows Application J# Project

Page 170: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

3. Next we need to add a reference to the SQLBase .NET Provider

4. Find Gupta SQLBase .Net Data Provider, Click Select and then OK.

Page 171: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

5. Rename Form1.jsl to frmSearch.jsl in the Solution Explorer

Page 172: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

6. Right-click on frmSearch.jsl and select View Designer

7. Now resize the Form and place the following controls on it from the Toolbox

Page 173: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Object Name Form frmSearch TextBoxes txtCompanyID

txtCompanyName txtStatus txtEmployeeID txtInvoiceNo txtInvoiceDate txtDatePaid txtAmountPaid

Query Command Buttons cmdFind cmdClearFields

Close Command Button cmdClose Navigation Command Buttons cmdNavigate0

cmdNavigate1 cmdNavigate2 cmdNavigate3

Label lblNavigate DataGrid DataGrid1

8. Now right-click on the form frmSearch and select View Code to see the following

9. Include the SQLBase .NET Provider Namespace, as indicated:

Page 174: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

10. Next, declare the global variables

19. Next, replace all occurrences of name Form1 with frmSearch

11. Add the CreateDataBindings() function to bind the TextBoxes with the database table columns to assist with the result set navigation

Page 175: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

12. Create the function to build the parent table result set

13. Add the function to handle the creation of the child table result set

Page 176: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

14. Next, we add code to handle the click event of the Find button.

15. Add code to handle the Click event of the Navigation buttons

Page 177: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

16. Add code to handle the click event of the Clear button

Page 178: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

17. Finally, handle the Click event of the Close button

18. Now Save the project and hit F5 to run the application

19. Click the Find button, then navigate the DataSet with the Navigation buttons

Page 179: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Tutorial 4

Using the form created in Tutorial 3, this Tutorial adds code to allow updates to child records; restricting updates on primary keys. This Tutorial also demonstrates drop-down column abilities and editable DataGrid columns

1. Start Visual Studio .NET 2. Create the directory \SQLBase 9.0\Tutorials\J#\Tut4\ 3. Copy the files JSharp_Tut3.vjsproj, frmSearch.jsl, frmSearch.resx &

AssemblyInfo.jsl to the new directory 4. Open the Project \SQLBase 9.0\Tutorials\J#\Tut4\ JSharp_Tut3.vjsproj 5. Rename the solution JSharp_Tut3 to JSharp_Tut4, and the project

JSharp_Tut3 to JSharp_Tut4

Page 180: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

6. Right-click the project JSharp_Tut4 and select properties 7. Change the Assembly Name and Default Package from JSharp_Tut3 to

JSharp_Tut4, and click OK

Page 181: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

8. Now right-click on frmSearch.jsl and select View Designer 9. Now add the Save button, change the background color of the Textboxes and

set the enabled property for the button and TextBoxes to false:

Page 182: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Object Name Save Command Button cmdSave

10. Right-click on the form and select View Code

11. Rename the Package JSharp_Tut3 to JSharp_Tut4

12. Declare the variables for this Tutorial and a Combobox, as follows:

13. Add a new function to setup the Combobox and DataGrid

Page 183: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

14. Add the following functions for the DataGrid and ComboBox Events

Page 184: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

15. Declare the variable BldUpdCmd in the function CreateInvoiceSet

Page 185: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

16. Then add the following for the DataGrid update and bind parameters:

17. Add code for FillSchema for the Adapter update and comment out the close connect line at the end of the function

Page 186: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

18. Add the highlighted line to the CreateCustomerSet function

19. Add the highlighted line to the cmdClearFields_Click event

20. Handle the click event for the Save button

Page 187: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

21. Add the EventHandlers in the function InitializeComponent

22. Access the properties for the DataGrid to setup the events as shown

Page 188: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Page 189: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

23. Save the project, and hit F5 to run 24. Click Find, navigate the master-detail records 25. Edit a color column in the DataGrid to change a color, and click Save

Page 190: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

26. If successful, the following will appear:

Page 191: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Tutorial 5

This Tutorial demonstrates the ability to retrieve and save graphics to SQLBase.

1. Start Visual Studio .NET 2. Create the directory \SQLBase 9.0\Tutorials\J#\Tut5\ 3. Copy the files JSharp.vjsproj, frmSearch.jsl, frmSearch.resx &

AssemblyInfo.jsl to the new directory 4. Open the Project \SQLBase 9.0\Tutorials\J#\Tut5\JSharp_Tut1.vjsproj 5. Rename the solution JSharp_Tut1 to JSharp_Tut5, the project

JSharp_Tut1 to JSharp_Tut5

6. Right-click the project JSharp_Tut5 and select properties 7. Change the Assembly Name and Default Package from JSharp_Tut1 to

JSharp_Tut5 and click OK

Page 192: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

8. Now right-click on frmSearch.jsl and select View Designer 9. Add a PictureBox object and the Save button as illustrated:

Object Name PictureBox photo Save Command Button cmdSave

Page 193: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

10. Change the Visible property of the PictureBox to False

11. Right-click on the form and select View Code

12. Rename the Package JSharp_Tut1 to JSharp_Tut5

13. Add the namespace for IO operations

14. Add the function to display the photo

Page 194: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

15. Add the highlighted lines to the function CreateDataBindings

16. Add the column PHOTO to the select list

Page 195: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

17. Call the ShowPhoto() function from each of the navigation button’s event

Page 196: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

18. Add the highlighted line to the cmdClearFields event

19. Handle the Save button click event

Page 197: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

20. Add the function to save the image to the database

21. Save the project, and hit F5 to run

22. Click on Find, and scroll the result set

Page 198: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

23. Now click on Save to open the following dialog

24. Select a gif or bmp and Click Open

25. You should receive a message box stating that the Image was updated

26. Click on Clear and then Find

27. Scroll through the result set to view the update

Page 199: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

ASP .NET Tutorials

Tutorial 1 This tutorial will walk you through creating code for connecting to the SQLBase Island database using the OLE DB Provider for SQLBase. Related set of data from the ORDER and ORDER_ITEM tables will be displayed in two different datagrids. You can view the detail rows related to any data row in the master datagrid, by clicking on the Show Details link.

We will use note pad to create the aspx file. Tutorial 2 will cover using Web Forms in a Visual Studio .NET project, using the SQLBase .NET Provider.

Step 1: Import the required namespaces

<%@ Import Namespace="System.Data" %>

<%@ Import Namespace="System.Data.OleDb" %>

Step 2: Set up the user interface

The UI mainly consists of 2 datagrids for master and details and a label for indicating exceptions.

Note that the master datagrid is wired up for handling ItemCommand.

<html>

<body>

<H2>Example: Master Detail Form</H2>

<form id="MasterDetail" runat="server">

<asp:DataGrid id="Master" runat="server"

BorderColor="black"

BorderWidth="1"

GridLines="Both"

CellPadding="3"

CellSpacing="0"

Font-Name="Verdana"

Font-Size="8pt"

HeaderStyle-BackColor="#aaaadd"

Page 200: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

SelectedItemStyle-BackColor="yellow"

AutoGenerateColumns="true"

OnItemCommand="Master_cmdShowDetails"

>

<Columns>

<asp:ButtonColumn Text="Show Details" HeaderText="Details" CommandName="CmdShowDetails">

</asp:ButtonColumn>

</Columns>

</asp:DataGrid>

<HR>

<asp:DataGrid id="Details" runat="server"

BorderColor="black"

BorderWidth="1"

GridLines="Both"

CellPadding="3"

CellSpacing="0"

Font-Name="Verdana"

Font-Size="8pt"

HeaderStyle-BackColor="#aaaadd"

AutoGenerateColumns="true"

/>

<br>

<asp:Label id="Label1" runat="server">Status</asp:Label>

</form>

</body>

Page 201: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Step 3: Initialize the data infrastructure.

1. Create an OleDbAdapter initialized with the master data from Order. Fill dataset m_ds with this datatable.

strSQL = "select * from Order"; cmd1 = new OleDbDataAdapter(strSQL, strConn); cmd1.Fill(m_ds, "tblOrder");

2. Create an OleDbAdapter initialized with the details data from Order_Item. Fill dataset m_ds with this datatable.

strSQL = "select Order_No, Item_No, Style_ID from Order_Item"; cmd = new OleDbDataAdapter(strSQL, strConn); cmd.Fill(m_ds, "tblOrderRow");

3. Create a DataRelation called OrdersRows with Order as the master and Order_Item as the detail.

m_rel = new DataRelation("OrdersRows", m_ds.Tables["Order"].Columns["Order_No"], m_ds.Tables["Order_Item"].Columns["Order_No"]); m_ds.Relations.Add(m_rel);

4. Bind the master datagrid to the data.

DataView dvMaster = m_ds.Tables["Order"].DefaultView; |Master.DataSource = dvMaster; Master.DataBind();

5. Initialize the datatable to be used for the details.

dt.Columns.Add(new DataColumn("Order_No", typeof(Int32))); dt.Columns.Add(new DataColumn("Item_No", typeof(Int32))); dt.Columns.Add(new DataColumn("Style_ID", typeof(Int32)));

Page 202: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Step 5: Display the detail rows corresponding to the selected master data row.

First traverse to the detail rows using the DataRelation object

rowCtr = e.Item.ItemIndex; //get the selected index from the master datagrid DataRow[] ChildRows = m_ds.Tables["Order"].Rows[rowCtr].GetChildRows("OrdersRows");

Now bind this data to the details datagrid. Since we cannot bind a DataRow[] directly to the datagrid, we transfer the data to a new datatable and then use that to bind to the DataGrid.

foreach(DataRow dr1 in ChildRows) { dr = dt.NewRow(); dr.ItemArray = dr1.ItemArray; dt.Rows.Add(dr); } DataView dv = new DataView(dt); Details.DataSource = dv; Details.DataBind();

Alternatives

Page 203: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

The approach used in this tutorial was basically used to demonstrate the DataRelation object. Here are some of the other alternative solutions:

Alternative 1. Bind the master and detail to the data tables Order and Order_Item and to display the details corresponding to the selected master row, apply a RowFilter to the Details DataView.

Alternative 2. Bind the master datagrid to the datatable Order and use a DataRelation object to encapsulate the master detail relationship, as in this tutorial. Display the data in a Table control created dynamically.

Tutorial 2

For this tutorial we will create a new form, modeling a parent-child relationship using a data grid for the child rows. We will walk through the process of creating the queries to populate the parent, and then retrieve the associated child records. We will add code to step through multiple parent records moving forward and backward through dataset, and moving through child records. We will use the Invoice and Invoice_Item tables of the SQLBase Island database.

1. Start Visual Studio .NET 2. Create a new ASP.NET Web Application under the Visual Basic Projects

Page 204: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

3. Next we need to add a reference to the SQLBase .NET Provider

4. Find Gupta SQLBase .Net Data Provider, Click Select and then OK.

Page 205: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

5. Now resize the Form and place the following controls on it from the Toolbox

Page 206: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

Object Name TextBoxes txtCompanyID

txtCompanyName txtStatus txtEmployeeID txtInvoiceNo txtInvoiceDate txtDatePaid txtAmountPaid

Navigation Command Buttons cmdNavigate0 cmdNavigate1 cmdNavigate2 cmdNavigate3

DataGrid DataGrid1

6. Now right-click on the Web Form and select View Code to see the following

7. Create a line above the first line and include the Namespace as indicated

8. Next, declare the global variables

Page 207: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

9. Create the function to build the parent table result set

10. Next we create the function to build the child table result set and bind it to the Data Grid

Page 208: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

11. Bind the TextBoxes with the DataSet

12. Setup the navigation buttons

Page 209: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com

13. Add the following to the Page_Load Event

14. Save the project and hit F5 to run

15. Navigate the result set

Page 210: SQLBase 9.0 Tutorial Guide

Gupta Technologies 975 Island Drive Redwood Shores, CA 94065 www.guptaworldwide.com