Develop a NetLogic for displaying a query result

This NetLogic script queries the database and displays the result by modifying the text of a label.
  1. In
    Project view
    , expand
    UI
    .
  2. Right-click
    QueryResultLabel
    and select
    New
    Runtime NetLogic
    .
  3. Hover-over the NetLogic, select
    Edit
    , and enter
    QueryResultLabelLogic
  4. Double-click the NetLogic.
    The external code editor opens.
  5. In the code editor, replace the existing code with the following code:
    #region StandardUsing using System; using System.Text; using UAManagedCore; using Store = FTOptix.Store; #endregion public class QueryResultLabelLogic : FTOptix.NetLogic.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 } [FTOptix.NetLogic.ExportMethod] public void RunQuery() { var project = FTOptix.HMIProject.Project.Current; var myStore = project.GetObject("DataStores").Get<Store.Store>("EmbeddedDatabase1"); object[,] resultSet; string[] header; var queryLabel = LogicObject.Owner as FTOptix.UI.Label; myStore.Query("SELECT COUNT(Column1) FROM Table1", out header, out resultSet); if (resultSet.Rank != 2) return; var rowCount = resultSet != null ? resultSet.GetLength(0) : 0; var columnCount = header != null ? header.Length : 0; if (rowCount > 0 && columnCount > 0) { var column1 = Convert.ToInt32(resultSet[0, 0]); StringBuilder sb = new StringBuilder("Record Count: "); sb.Append(column1); var queryResultLabel = LogicObject.Owner as FTOptix.UI.Label; queryResultLabel.Text = sb.ToString(); } } }
  6. Save the code.
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.