Some content on this site is available only to logged-in subscribers. Contact Us for information on becoming a subscriber.

InSource.Solutions | InSource Training | InSource Client Portal
InSource Solutions Logo
Log In Sign Up
InSource.Solutions InSource Training InSource Client Portal Log In Sign Up
  • Home
  • AVEVA Application Server
  • AVEVA Application Server Tech Notes

TN Appsvr142 How to query a SQL database and display in DataGrid View in Archestra Graphic

Last updated: February 28th, 2025

Description

  • Author: Michael Viteri
  • Published: February 28th, 2025

Details:

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.

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 fields 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();
  1. 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.

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

Confirmation of Success

Data is displayed in the grid.

sql query datagrid display
Give feedback about this article

Recommended articles

TN 1394 Error when Deploying: Remote Node's UserID/Password don't match GR Node's

Read More

TN 1366 Managing your Standalone InTouch Application in the Galaxy

Read More

Resolving "Open: Memory on the computer is low. New editor can't be launched."

Read More

TN 1040 No Alarms in Window Viewer

Read More
Support Icon

CONTACT SUPPORT

How to reach us

10800 Midlothian Turnpike Tpke, Suite 209, Richmond, VA 23235

1.877.INSOURCE

Technical Support - 1.888.691.3858

Contact Us

  • InSource Solutions
  • InSource Training
  • InSource Client Portal
  • Log In
InSource Solutions Logo

© 2025 InSource Solutions. All Rights Reserved.

Knowledge Base Software powered by Helpjuice

Expand