You are on page 1of 12

13/07/12 wwGenericSQLGrid

wwGenericSQLGrid
All Tech Notes and KBC D documents and software are provided "as is" without warranty of any kind. See the Terms of Use for more
information.

Topic#: 001046
C reated: July 2002

Introduction
The wwGenericSQLGrid is a data access object written to operate within the InTouch ActiveX container. The object can
be used for a grid representation of data from a relational database. The current release is recommended to access MS
SQL Server via OLEDB. The object's appearance can be modified by the settings on the property page as well as through
methods and properties at runtime.

Installation is simple and takes advantage of the Window installer. The grid is installed by running the
wwGenericSQLGrid.msi file that is part of the distribution package. Although this control was created specifically for use
within InTouch it can be used in any suitable ActiveX container. An example of a use within InTouch might be to give an
operator visibility into the customer order system allowing them to view the daily schedule. Another use might be to
access recipe information and extract that data for use in the control system.

Installing the wwGenericSQLGrid


The wwGenericSQLGrid object should work with any version of InTouch that supports ActiveX running on any InTouch
supported Operating System. This object has been installed and tested using InTouch 7.11 running on Windows2000 and
WindowsXP.

Unzip the installation files to a temporary directory. Locate the wwGenericSQLGrid.msi file. This package will be installed
using the Microsoft Installer feature of Windows. Once the file is located double-click on the .msi file.

Download the wwGenericSQLGrid.zip file.

1. Unzip the installation .msi file to a temporary directory.

2. Double-click the wwGenericSQLGrid.msi file within the temp directory.

3. Windows Installer will take you through the necessary steps to install wwGenericSQLGrid.

fa.sammicomputer.co.kr/TECH/html/t001046.htm 1/12
13/07/12 wwGenericSQLGrid

4. Click Next to continue with the installation.

5. Click the I Agree option button to continue the installation process.

6. Specify the location where the files will be installed.

fa.sammicomputer.co.kr/TECH/html/t001046.htm 2/12
13/07/12 wwGenericSQLGrid

7. Click Next to confirm the installation.

8. After the installation is complete, click Close.

fa.sammicomputer.co.kr/TECH/html/t001046.htm 3/12
13/07/12 wwGenericSQLGrid

wwGenericDataGrid is now ready to use within your environment.

Installing the GenericDataGrid


The GenericDataGrid can be used in any ActiveX container. This grid has been written and tested within the InTouch
container.

Utlizing the GenericDataGrid Within InTouch


To install the control within InTouch, you must register the control with the InTouch development environment.

1. Start InTouch WindowMaker.

2. Select Configure/Wizard/ActiveX Installation.

fa.sammicomputer.co.kr/TECH/html/t001046.htm 4/12
13/07/12 wwGenericSQLGrid

3. Click the ActiveX Control Installation tab.

4. Scroll through the list of Available ActiveX controls and select wwGenericSQLGrid.Grid.

5. Click Install.

Create a New Window for Placement of the Control


1. Create a new window within WindowMaker.

2. Click the wizard hat icon from the toolbar.

fa.sammicomputer.co.kr/TECH/html/t001046.htm 5/12
13/07/12 wwGenericSQLGrid

3. Double-click the Grid Control icon.

4. Click OK.

5. Click in the area of the window on which to place the control.

Use the Application Within an ActiveX Container


Properties
1. Double-click the control.

fa.sammicomputer.co.kr/TECH/html/t001046.htm 6/12
13/07/12 wwGenericSQLGrid
The Grid1 Properties dialog box opens:

The following table lists the available properties along with a description and data type.

Property Name Type Description R/W


The name of the server the grid is connecting
ServerName String R/W
to.
The name of the database the object is
DatabaseName String R/W
connecting to.
UserName String The user ID to be used for the connection. R/W
Password String The password being used for the connection. R/W
Caption String Sets or reads the caption from the grid object. R/W
FillColor Sets or reads the objects fill color. R/W
FillStyle Sets or reads the objects fill style. R/W
Font Sets or reads the grids font selection. R/W
Set or reads the maximum records to be
MaxRecords Long R/W
returned to the grid. Zero indicates all records.
SQLString String Sets or reads the current SQL String. R/W
RowCount Long Reads the current row count of the grid. R
Read the end of file status. (-1 = true, 0 =
EOF Boolean R
false).
Enabled Boolean Sets or reads the enabled state of the control. R
Read the beginning of file status. (-1 = true, 0
BOF Boolean R
= false).
Sets or reads the value for the connection
ConnectionString String R/W
string.
Sets or reads the value for the connection
ConnectionTimeOut Long R/W
timeout.
Sets or reads the value for displaying column
ColumnHeaders Boolean R/W
headings.

Methods
ActiveX control methods are similar to ActiveX control properties. ActiveX control methods are accessed through ActiveX
Event scripts and/or InTouch QuickScripts.

1. Double-click the control.

The Grid1 Properties dialog box opens:

fa.sammicomputer.co.kr/TECH/html/t001046.htm 7/12
13/07/12 wwGenericSQLGrid

2. Double-click a blank cell in the Script column.

The ActiveX Event Scripts editor opens:

3. Click ActiveX...

The ActiveX Control Browser dialog box opens:

fa.sammicomputer.co.kr/TECH/html/t001046.htm 8/12
13/07/12 wwGenericSQLGrid

The following table describes the methods are available to use in a script.

Return
Method Name Description
Type
Select this method when changing connection
parameters. Note that this method also calls the
Connect() N/A execute method to verify the connection to the
database, you must set the SQLString property
before executing the connect.
Connect();
Select this method to connect to a data source
using an ADO connection string. See ADO
ConnectWithString N/A documentation for further information on
connection strings. The Examples section of this
Utility lists common examples.
ConnectWithString("INSERT CONNECTION STRING");
This method will clear the grid of it's current
Clear() N/A
contents, the recordset will still be available.
Clear();
Select this method when changing the SQLString
Execute() property. This will execute the query and return the
results to the grid.
Execute();
This method takes a row and column number and
GetRowColumnValue() String
returns the value of that cell.
StringTag = GetRowColumnValue(Row as int,
Column as int);
GetSelectedCellValue() String Returns an integer value of the selected row.
IntegerTag = GetRowNumber();

GetColumnNumber() Long Returns an integer value of the column the selected


cell, if no specific cell is selected it will return a -1.
IntegerTag = GetColumnNumber();
Returns the value from the column specified in the
ColumnValue() String
selected row.
StringTag = GetSelectedRowValue(Column as int);
MoveFirst() N/A Moves the selection to the first row in the grid.
MoveFirst();

fa.sammicomputer.co.kr/TECH/html/t001046.htm 9/12
13/07/12 wwGenericSQLGrid
MoveLast() N/A Moves the selection to the last row in the grid.
MoveLast();
MovePrevious() N/A Moves the selection to the previous row in the grid.
MovePrevous();
Movenext() N/A Moves the selection to the next row in the grid.
Movenest();
About() N/A Displays the about box.
About();
Adds a string value to the SQLString property, this
SQLStringAppend() N/A method also pads a space at the beginning of the
added string.
SQLStringAppend("Where city = 'Boston'");
Disconnect() N/A Disconnects the current ADO connection.
Disconnect();

Events
Click - This event is triggered every time the user clicks on the area of the control.

These events can be used in conjunction with the methods and properties to control the behavior of the control as well as
to extract data from user selections.

Examples
The distribution package you received should contain an InTouch demo application that exercises all the capabilities of the
wwGenericDataGrid.

The following code can be run directly in InTouch quickscripts.

Below is an example to connect the grid to a Database:

#Grid1.Server = Server;
#Grid1.Database = Database;
#Grid1.UserID = UserID;
#Grid1.Password = Password;
#Grid1.Connect();

To get a specific value from a cell:

Selection = #Grid1.GetRowColumnValue( Row, Column);

To get the selected value:

Selection = #Grid1.GetSelectedCellValue();

To get the number of rows currently listed in the grid:

NumberOfRows = #Grid1.NumberOfRows;

The example above utilizes an object named Grid1. Dropping an instance of the object on a window and naming it Grid1
makes it able to use the example exactly as it appears.

Since there is no method or property to change the column headings on the grid, utilize your query to accomplish this
task. This can be done by specifying AS with a title in your query. The following is a simple example that selects the last
name from the author's table and displays it as Last Name.

select au_lname as 'Last Name' from authors

The name of the column is au_lname but the grid will display it as Last Name.

Connection strings can be used to connect to a variety of different data sources. To do this you would use the
ConnectWithString() method and pass the proper connection string. For more details on connection strings check ADO
documentation. The following are a few examples.

ODBC
fa.sammicomputer.co.kr/TECH/html/t001046.htm 10/12
13/07/12 wwGenericSQLGrid
Provider=MSDASQL.1;Password=PWD;Persist Security Info=True;User ID=UID;Data Source=TheDSN;Initial Catalog=THEDB
ORACLE
Provider=MSDAORA.1;Password=PWD;User ID=UID;Data Source=OrServer;Persist Security Info=True
SQLServer
Provider=SQLOLEDB.1;Password=PWD;Persist Security Info=True;User ID=UID;Initial Catalog=TheDATABASE;Data
Source=SQLServer
Jet 3.51
Provider=Microsoft.Jet.OLEDB.3.51;Password=myPWD;Persist Security Info=True;User ID=myUID;Data Source=MyDB.mdb
Jet 4.0
Provider=Microsoft.Jet.OLEDB.4.0;Password=myPWD;Persist Security Info=True;User ID=myUID;Data
Source=C:\NWIND.MDB

The following table lists OLE DB connection strings for several common data sources:

Data Source OLE DB Connection String

Data Source OLE DB Connection String


Provider=Microsoft.Jet.OLEDB.4.0;Data
Microsoft® Access
Source=physical path to .mdb file
Provider=SQLOLEDB.1;Data Source=path to
Microsoft SQL Server
database on server
Provider=MSDAORA.1;Data Source=path to
Oracle
database on server
Microsoft Indexing Service Provider=MSIDXS.1;Data Source=path to file

To provide for backward compatibility, the OLE DB Provider for ODBC, supports ODBC connection string syntax. The
following table lists commonly used ODBC connection strings:

Data Source Driver ODBC Connection String


Driver={Microsoft Access Driver
Microsoft® Access
(*.mdb)};DBQ=physical path to .mdb file
SQL Server DRIVER={SQL Server};SERVER=path to server
DRIVER={Microsoft ODBC for
Oracle
Oracle};SERVER=path to server
Driver={Microsoft Excel Driver
Microsoft Excel (*.xls)};DBQ=physical path to .xls file;
DriverID=278
Driver={Microsoft Excel Driver
Microsoft Excel 97 (*.xls)};DBQ=physical path to .xls
file;DriverID=790
Driver={Microsoft Paradox Driver
Paradox (*.db)};DBQ=physical path to .db
file;DriverID=26
Driver={Microsoft Text Driver
Text (*.txt;*.csv)};DefaultDir=physical path to .txt
file
Driver={Microsoft Visual FoxPro
Microsoft Visual FoxPro® (with a
Driver};SourceType=DBC;SourceDb=physical
database container)
path to .dbc file
Driver={Microsoft Visual FoxPro
Microsoft Visual FoxPro (without a
Driver};SourceType=DBF;SourceDb=physical
database container)
path to .dbf file

Technical Support
This object is provided as is and is not supported through Wonderware Technical Support. A certain level of testing has
been completed to insure the control operates in the manner described in the manual, but as with any add-in control, no
guarantees can be given as to how this object will perform within a given application. It is suggested that you test your
required functionality prior to deploying the control in an application.

B. Martin

For technical support questions, send an e-mail to support@wonderware.com.

fa.sammicomputer.co.kr/TECH/html/t001046.htm 11/12
13/07/12 wwGenericSQLGrid

back to top

©2012 Invensys Systems, Inc. All rights reserved. No part of the material protected by this copyright may be reproduced or utilized in any
form or by any means, electronic or mechanical, including photocopying, recording, broadcasting, or by any information storage and retrieval
system, without permission in writing from Invensys Systems, Inc.

fa.sammicomputer.co.kr/TECH/html/t001046.htm 12/12

You might also like