TN Appsvr142 How To Query A SQL Database and Display in DataGrid View in Archestra Graphic - InSource KnowledgeCenter PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

 

InSource Home InSource Training Submit a Support Ticket My Preferences

 How can we help you? Username Password Sign in 


  Home »  Wonderware Application Server »  Tech Notes

TN Appsvr142 How to query a SQL database and


display in DataGrid View in Archestra Graphic
Last updated: Jan 30, 2016

 Table of contents

                            Tech Note                 
 
Description

This article from InSource shows how to query data from a SQL database and display in a DataGrid in an Archestra Graphic.

Author: Mike Viteri
Published: 1/2/2015
Applies to: System Platform

How and When to Use this Guide

When you want to display data from a SQL database inside an datagridview Archestra Graphic

Instructions

You will need to make sure your datagridview is imported. If not available. Please refer to this technote.

1. You will need to create an Archestra Graphic Symbol. You will need to bring in the datagrid view control and create a button.
 

2. Click on the button and create a action script. You will use the following script to create a connection to your SQL database. 

Under sDBConnStr you will need to replace your Server, Database,UserID and Password to match your system.
 

For sSQL  you will need to insert your query for data you want to showup in the datagrid view.

Make sure the datagridview you are using is "datagridview1" if not change the script below to make the datagridview you are using.
 
The complete script is pasted below in between the lines

--------------------------------------------------------------------------------------------------------------------------------------

Dim objDB As System.Data.SqlClient.SqlConnection;


Dim objCmd As System.Data.SqlClient.SqlCommand;
Dim objDR As System.Data.SqlClient.SqlDataReader;
Dim objTbl As System.Data.DataTable; 
Dim sDBConnStr As String;
Dim sSQL As String;
Dim bOk As Boolean;
 
sDBConnStr = "Server=MV20142;Database=Runtime;User Id=sa;Password=I$$Insource1234;"; 

'' Connect and open the database


objDB = New System.Data.SqlClient.SqlConnection(sDBConnStr);
objDB.Open(); 

sSQL = "SELECT [DateTime],[TagName],[Value] FROM [Runtime].[dbo].[v_AnalogHistory] Where TagName = 'systimesec'"; 

'' Invoke the SQL command 


objCmd = New System.Data.SqlClient.SqlCommand(sSQL, objDB); 

'' Retrieve the queried elds from the query into the reader
objDR = objCmd.ExecuteReader(); 

'' Is there a result to the query?


bOk = objDR.HasRows; 

If bOk <> True Then


  LogMessage(  "INFO: SQL Reader -:- No rows returned. [" + sSQL + "]");
Else

  '' Instanciate & Load the results into a table object


  objTbl = New System.Data.DataTable;
  objTbl.Load(objDR);  

  '' Load the table into the grid


 DataGridView1.DataSource = objTbl; 

Endif;

DataGridView1.AutoResizeColumns();
 
'' Cleanup
objDR.Close();
objDB.Dispose();
objCmd.Dispose();
objTbl.Dispose();

3. You will need to embed your symbol that has the grid and button into an Intouch Window. Go to runtime. You should see your grid
and button. when you click the button the data should be returned from the sql into the data grid.

 
--------------------------------------------------------------------------------------------------------------------------------------

Con rmation of Success

Data is displayed in the grid.


Back to top TN Appsvr141 Advanced Obj… TN AppSvr143 Con guring Th… 

Recommended articles

 Setting up the SQL Server 2005 Express Database  Changing the Default Location for New SQL Databases

 Using Excel to Report on Wonderware Alarms  Moving the Alarm Database to a different hard drive

 Using SQLAccess Scripting Within InTouch


Explains how to connect to and manipulate data in an outside database using the built in SQLAccess scripting functions in
InTouch.

Article type: Topic Articleclass: App Server TN General Article Content: Native IT Article Class: NetSuite

Tags: Data Grid, SQL, stage: nal

InSource Corporate Sales: 877.467.6872 Login


Technical Support: 888.691.3858
Use of content on this site means you agree to InSource Terms and Conditions HERE

You might also like