# Showing Query Results

Query results can be displayed either on a Page using a Table User Controls, or by accessing the individual results of a query using tags.

The following example illustrates how publish the results of a query, using a script:

    // The Database is a SQLite database, named "new_database".
    // The Table is named "MyTable" with the following fields, in this order: Value(Double), Active(Boolean)
    // The Query is named "MyQ"; select * from MyTable.
    // There are two examples below; one which uses indexes, and another which uses column names.
    // No additional references are needed for other dlls.
    // Two integer data type tags need to be created: $TotalUsingIndex &  $TotalUsingName

    $Databases.new_database.MyTable.MyQ.Run();

    DataRow[] rows = $Databases.new_database.MyTable.MyQ.QueryResults;

    double total = 0;

    // using index
    foreach (var row in rows) {
      double value = Convert.ToDouble(row[0]);
      bool isActive = Convert.ToBoolean(row[1]);

      if (isActive)
          total+=value;
    }
    // add label to HMI bound to tag below
    $TotalUsingIndex = total;

    total=0;

    // using column name (slower than index)

     foreach (var row in rows) {
     double value = Convert.ToDouble(row["Value"]);
     bool isActive = Convert.ToBoolean(row["Active"]);

       if (isActive)
          total+=value;
     }

    // add label to HMI bound to tag below
    $TotalUsingName = total;
    return $Databases.new_database.MyTable.MyQ.RowCount;//