You are on page 1of 14

wwGenericSQLGrid

. 1 14

https://gcsresource.invensys.com/support/Wonderware/UtilityReadme/t...

wwGenericSQLGrid

All Tech Notes, Tech Alerts and KBCD documents and software are provided "as is" without warranty of any
kind. See the Terms of Use for more information.
Topic#: 001046
Created: July 2002
Updated: May 2007
Updated: July 2008

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 9.5 Patch 03 running on Windows2003 SP2.
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 the .msi file.
To download the file, close this document window and click the Confirm Download
button.

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


2. Double-click the wwGenericSQLGrid.msi file within the temp directory (Figure 1
below):

22.09.2016 9:21

wwGenericSQLGrid

. 2 14

https://gcsresource.invensys.com/support/Wonderware/UtilityReadme/t...

FIGURE 1: DOUBLE-CLICK

THE WWGENERIC SQLGRID

FILE

Windows Installer begins the necessary steps to install wwGenericSQLGrid (Figure 2


below):

FIGURE 2: WINDOWS INSTALLER -

WWGENERIC SQLGRID

SETUP

3. Click Next to continue with the installation.


The License Agreement Wizard appears:

22.09.2016 9:21

wwGenericSQLGrid

. 3 14

https://gcsresource.invensys.com/support/Wonderware/UtilityReadme/t...

FIGURE 3: LICENSE AGREEMENT


4. Click the I Agree option button to continue the installation process.
The Select Installation Folder Wizard appears:

FIGURE 4: INSTALLATION LOCATION


5. Specify the location where the files will be installed.
6. Click Next.

22.09.2016 9:21

wwGenericSQLGrid

. 4 14

https://gcsresource.invensys.com/support/Wonderware/UtilityReadme/t...

The Confirm Installation Wizard appears:

FIGURE 5: CONFIRM INSTALLATION


7. Click Next.
After running the installation, the Installation Complete Wizard appears:

FIGURE 6: INSTALLATION COMPLETE


8. Click Close.

22.09.2016 9:21

wwGenericSQLGrid

. 5 14

https://gcsresource.invensys.com/support/Wonderware/UtilityReadme/t...

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.

Registering the GenericDataGrid Within InTouch


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

1. Launch InTouch WindowMaker.

FIGURE 7: LAUNCH WINDOWMAKER


2. Select Configure/Wizard/ActiveX Installation.
3. Select the ActiveX Control Installation tab.
4. Scroll down the list until the control appears (wwGenericSQLGrid.grid):

22.09.2016 9:21

wwGenericSQLGrid

. 6 14

https://gcsresource.invensys.com/support/Wonderware/UtilityReadme/t...

FIGURE 8: ACTIVEX CONTROL INSTALLATION


5. Click Install, then Close.

Create a New Window for the Control


1. Create a new window within WindowMaker.
2. Click the Wizard Hat icon on the toolbar.

FIGURE 9: WIZARD HAT ACTIVEX CONTROLS


3. Double-click the Grid Control icon.
4. Click OK.
5. Click in the area of the window on which to place the control.
The control appears with its sizing handles:

22.09.2016 9:21

wwGenericSQLGrid

. 7 14

https://gcsresource.invensys.com/support/Wonderware/UtilityReadme/t...

FIGURE 10: ACTIVEX CONTROL PLACEMENT

ON

WINDOW

The object is ready for configuration and use.

Use the Application Within an ActiveX Container


Properties
1. Double-click the control.
The Grid1 Properties dialog box appears:

FIGURE 11: GRID PROPERTIES


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

Property Name

Type

Description

R/W

ServerName

String

The name of the server the grid is


connecting to.

R/W

22.09.2016 9:21

wwGenericSQLGrid

. 8 14

https://gcsresource.invensys.com/support/Wonderware/UtilityReadme/t...

DatabaseName

String

The name of the database the


object is connecting to.

R/W

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

MaxRecords

Long

Set or reads the maximum records


to be returned to the grid. Zero
R/W
indicates all records.

SQLString

String

Sets or reads the current SQL


String.

RowCount

Long

Reads the current row count of the


R
grid.

EOF

Boolean

Read the end of file status. (-1 =


true, 0 = false).

Enabled

Boolean

Sets or reads the enabled state of


the control.

BOF

Boolean

Read the beginning of file status.


(-1 = true, 0 = false).

ConnectionString

String

Sets or reads the value for the


connection string.

R/W

ConnectionTimeOut Long

Sets or reads the value for the


connection timeout.

R/W

ColumnHeaders

Sets or reads the value for


displaying column headings.

R/W

Boolean

R/W

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

1. Select the Events tab.

FIGURE 12: EVENTS TAB FIELD

22.09.2016 9:21

wwGenericSQLGrid

. 9 14

https://gcsresource.invensys.com/support/Wonderware/UtilityReadme/t...

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


The ActiveX Event Scripts editor opens (Figure 13 below).
3. Select Insert/ActiveX...

FIGURE 13: ACTIVEX SCRIPT EDITOR


The ActiveX Control Browser dialog box opens:

22.09.2016 9:21

wwGenericSQLGrid

. 10 14

https://gcsresource.invensys.com/support/Wonderware/UtilityReadme/t...

FIGURE 14: ACTIVEX CONTROL METHOD/PROPERTY BROWSER


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

Method Name

Connect()

Return
Description
Type

N/A

Select this method when changing


connection parameters. Note that this
method also calls the execute method
to verify the connection to the
database, you must set the SQLString
property before executing the
connect.
Connect();

ConnectWithString

N/A

Select this method to connect to a


data source using an ADO connection
string. See ADO documentation for
further information on connection
strings. The Examples section of this
Utility lists common examples.
ConnectWithString("INSERT
CONNECTION STRING");

Clear()

N/A

This method will clear the grid of it's


current contents, the recordset will
still be available.
Clear();

Execute()

Select this method when changing


the SQLString property. This will
execute the query and return the
results to the grid.
Execute();

GetRowColumnValue() String

This method takes a row and column


number and returns the value of that
cell.
StringTag =
GetRowColumnValue(Row as int,
Column as int);

22.09.2016 9:21

wwGenericSQLGrid

. 11 14

https://gcsresource.invensys.com/support/Wonderware/UtilityReadme/t...

GetSelectedCellValue() String

Returns an integer value of the


selected row.
IntegerTag = GetRowNumber();

GetRowNumber()

Long

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();

ColumnValue()

String

Returns the value from the column


specified in the selected row.
StringTag =
GetSelectedRowValue(Column as
int);

MoveFirst()

N/A

Moves the selection to the first row in


the grid.
MoveFirst();

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

About()

N/A

Moves the selection to the next row in


the grid.
Movenest();
Displays the about box.
About();

SQLStringAppend()

N/A

Adds a string value to the SQLString


property, this 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();
The contents of wwGenericDataGrid
are copied to the specified Excel File
and then Printed to default printer.
bPrint = 1: Excel File is printed to
default printer

PrintGrid()

N/A

bPrint = 0: Excel File is NOT printed.


The user has the choice of opening
the Excel file and printing it later
using Excel.
applPATH: a string for complete path
eg: c:\myfolder\. If applPATH is
blank i.e , the default path
c:\temp\ is used.
FileName: a string specifying the
Excel filename. If it is blank, a default
filename of myXLBook1.xls is used.
PrintGrid( applPATH as String,
FileName as String, bPrint as
Boolean);

22.09.2016 9:21

wwGenericSQLGrid

https://gcsresource.invensys.com/support/Wonderware/UtilityReadme/t...

GetColumnWidth()

Returns column width for a given


Integer column identified by its 0-based
index.
IntegerTag =
GetColumnWidth(Column as integer);

SetColumnWidth()

N/A

Sets column width for a given column


identified by its 0-based index.
SetColumnWidth(
SelectedColumnNumber as Integer,
iColWidth as Integer);

SetColumnVisible()

N/A

Makes given Columns Visible /


Invisible
SetColumnVisible( ColumnIndex As
Integer, VisibleState As Boolean)
VisibleState = 1, makes given column
visible
VisibleState = 0, makes given column
invisible

GetCoulmnVisible()

Boolean

Returns the visibility status (Boolean)


for the given Column.
DiscreteTag = GetColumnVisible(
ColumnIndex As Integer )
DiscreteTag = 1, means Visible
DiscreteTag = 0, means not Visible

Events
Click - This event is triggered every time the user clicks on the area of the control.
SelChange - This event is triggered every time the user clicks on the "row selector" i.e the
grey area on the far left hand side of the Grid.
SelectionChanged - This event is triggered when the user changes rows by clicking directly
within a cell.
ColumnWidthChanged - This event is triggered when the Column width is changed.
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();
#Grid1.PrintGrid( "c:\", "myEbook.xls", 1);
To get a specific value from a cell:

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


To get the selected value:

. 12 14

22.09.2016 9:21

wwGenericSQLGrid

https://gcsresource.invensys.com/support/Wonderware/UtilityReadme/t...

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 possible 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
Connection strings can be used to connect to a variety of different data sources.
To connect to a data source, you would use the ConnectWithString() method and pass the proper
connection string. For more details on connection strings check ADO documentation.
The following strings are a provided for common data sources:

ODBC

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 OLE DB data sources:

. 13 14

Data Source

OLE DB Connection String

Microsoft Access

Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=physical path to .mdb file

22.09.2016 9:21

wwGenericSQLGrid

https://gcsresource.invensys.com/support/Wonderware/UtilityReadme/t...

Microsoft SQL Server

Provider=SQLOLEDB.1;Data Source=path
to database on server

Oracle

Provider=MSDAORA.1;Data Source=path to
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

Microsoft Access

Driver={Microsoft Access Driver


(*.mdb)};DBQ=physical path to .mdb
file

SQL Server

DRIVER={SQL Server};SERVER=path
to server

Oracle

DRIVER={Microsoft ODBC for


Oracle};SERVER=path to server

Microsoft Excel

Driver={Microsoft Excel Driver


(*.xls)};DBQ=physical path to .xls file;
DriverID=278

Microsoft Excel 97

Driver={Microsoft Excel Driver


(*.xls)};DBQ=physical path to .xls
file;DriverID=790

Paradox

Driver={Microsoft Paradox Driver


(*.db)};DBQ=physical path to .db
file;DriverID=26

Text

Driver={Microsoft Text Driver


(*.txt;*.csv)};DefaultDir=physical path
to .txt file

Microsoft Visual FoxPro (with a


database container)

Driver={Microsoft Visual FoxPro


Driver};SourceType=DBC;
SourceDb=physical path to .dbc file

Microsoft Visual FoxPro (without a


database container)

Driver={Microsoft Visual FoxPro


Driver};SourceType=DBF;
SourceDb=physical 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 ensure 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.
Created by: B. Martin
Updated by: Prerana Kulkarni
Tech Notes are published occasionally by Wonderware Technical Support. Publisher: Invensys Systems, Inc.,
26561 Rancho Parkway South, Lake Forest, CA 92630. There is also technical information on our software
products at Wonderware Technical Support.

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


back to top
2016 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 anyinformation storage and retrieval system, without permission in writing from
Invensys Systems, Inc. Terms of Use.

. 14 14

22.09.2016 9:21

You might also like