Using Zenon 8.20 variables in scadaAddin script

Using Zenon 8.20 variables in scadaAddin script

Hi,
I just started working with scada addins and came up with a little problem: I am trying to write a script that takes variable values that are already imported in Zenon 8.20 and send them to database. I tested SQL querry part of the script and it works fine. However it doesn't seem to assign variables correctly and I wasn't able to find a good example that shows how to properly do it. Can you please help me? here is the script that I wrote:

using System;
using Scada.AddIn.Contracts;
using Scada.AddIn.Contracts.Variable;
using System.Data.SqlClient;
namespace IMM137
{
///
/// Description of Project Wizard Extension.
///

[AddInExtension("Your Project Wizard Extension Name", "Your Project Wizard Extension Description")]
public class ProjectWizardExtension : IProjectWizardExtension
{
#region IProjectWizardExtension implementation
public void Run(IProject context, IBehavior behavior)
{
// enter your code which should be executed on triggering the function "Execute Project Wizard Extension" in the SCADA Runtime
IVariable Date = context.VariableCollection["(date variable name as shown in ZENON)"];
IVariable Time = context.VariableCollection["(time variable name as shown in ZENON)"];
IVariable Produce = context.VariableCollection["(Produce variable name as shown in ZENON)"];

SqlConnection con = new SqlConnection("Data Source=MY_SERVER;Database=MY_DB;User Id=MY_ID;Password=MY_PASSWD");
con.Open();
if (con.State == System.Data.ConnectionState.Open)
{
string q = "INSERT into [MY_DB].[dbo].[MY_TABLE]([Date],[Time],[Produce]) VALUES('{$Date}', '{$Time}', {$Produce})";
SqlCommand cmd = new SqlCommand(q, con);
cmd.ExecuteNonQuery();
}
}
#endregion
}
}



This is a migrated post! Originally posted on 30.10.2019 by user lsimas3. Please be aware that information can be outdated.