Develop a NetLogic for inserting random values

This NetLogic script inserts random values into the
Table1
table of the database.
Prerequisites
Set the default external code editor. See Set the default code editor.
  1. To develop the NetLogic
  2. In
    Project view
    , expand the
    DataStores
    folder.
  3. Right-click a database and select
    New
    Runtime NetLogic
    .
  4. Hover-over the NetLogic, select
    Edit
    Edit
    , and enter
    EmbeddedDatabase1NetLogic
  5. Double-click the NetLogic.
    The external code editor opens.
  6. In the code editor, replace the existing code with the following code:
    #region Using directives using System; using FTOptix.HMIProject; using FTOptix.NetLogic; using FTOptix.Store; #endregion public class EmbeddedDatabase1NetLogic : BaseNetLogic { public override void Start() { // Insert code to be executed when the user-defined logic is started } public override void Stop() { // Insert code to be executed when the user-defined logic is stopped } [ExportMethod] public void InsertRandomValues (){ // Get the current project folder. var project = Project.Current; // Save the names of the columns of the table to an array string[] columns = { "Column1", "Column2", "Column3" }; // Create and populate a matrix with values to insert into the odbc table var rawValues = new object[1000, 3]; Random randomNumber = new Random (); for (UInt16 i = 0; i < 1000; ++i) { // Column1 rawValues[i, 0] = i; // Column2 rawValues[i, 1] = randomNumber.Next(0, 5000); // Column3 rawValues[i, 2] = randomNumber.NextDouble() * 5000; } var myStore = LogicObject.Owner as Store; // Get Table1 from myStore var table1 = myStore.Tables.Get<Table>("Table1"); // Insert values into table1 table1.Insert(columns, rawValues); } }
  7. Save the code.
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.