Configure database connections and execute queries.
Tutorials → Business Operations Tutorial → Datasets Module Tutorial
This Tutorial Teaches you to:
Configure database connections
Create queries with parameters
Display data in tables
Prerequisites:
1. Configure Database Connection
- Navigate to Datasets → DBs
- Click Plus icon to add database
Option A: Use Default SQLite
Name: ProductionDB
Provider: SQLite Data Provider
Database: .Net Framework Data Provider for SQLite
ConnectionString: [Auto-configured]Option B: SQL Server
Name: ProductionDB
Provider: SqlClient Data Provider
Database: SQL Server Database
ConnectionString:
Data Source=SERVER\INSTANCE;
Initial Catalog=Production (your database name);
- Click Test → Should show "OK"
Info
These tables will not be used further in this Tutorial, once there is no data available. If you have a database table with data, feel free to use, if not you can use the Table created on the Historian Module Tutorial
2. Create Simple Query
- Go to Datasets → Queries
- Click Plus icon
- Configure:
- Name:
ActiveOrders
- Name:
- Click OK
- Change the DB column to TagHistorian
- Double-click SqlStatement to edit:
SELECT "TankFarm/Tank1/Temperature" FROM ProcessData
3. Add Dynamic Parameters
- Go to Datasets → Queries
- Double-click SqlStatement to edit
- Edit SQL with tag placeholders:
SELECT "TankFarm/Tank1/Temperature" FROM ProcessData WHERE UTCTimestamp_Ticks >= (strftime('%s', {Tag.TankFarm/Tank1/Temperature.Timestamp}, '-10 days') * 10000000) + 621355968000000000
- It is important to remember that historian data is in UTCTicks, thats why the time calculation must to be done
4. Display Query Results
- Open Displays → Draw
- Add DataGrid control
- Double-click and go to Settings
- Set properties:
- DataSource:
@Dataset.Query.ActiveOrders
- DataSource:
- Run solution
- Verify data appears in grid
5. Execute from Script
Create button to run query:
- Add button to display
- Double-click and go to Dynamics:
- Check Action and configure:
- Event: MouseLeftButtonDown
- Action: RunScript
- Click New
- The CodeBehind display will automatically open
- Add the following script:
public void MouseLeftButtonDown1(object sender, System.Windows.Input.InputEventArgs e)
{
DataTable results = @Dataset.Query.ActiveOrders.SelectCommand();
}
Debug
You can use the Debugging Scripts Code with Microsoft Visual Studio to debug this piece of code and view the values in the "results" variable
6. Test Your Configuration
- Start runtime
- Open Datasets → Datasets Monitor
- Verify:
- LastStatus
- RowCount
- No errors in LastStatusMessage
- Check DataGrid displays:
- Data refreshes automatically
→ Modules / Business Operations / Datasets Module → Tutorials / Business Operations / Datasets Module Tutorial → How-to Guides / I Business Operations / Datasets Module How-to Guide → Technical Reference / Business Operations / Datasets Module ReferenceDatasets Module Links
Explanation - to understand concepts
Tutorials - to learn by doing
How-to Guides - to accomplish specific tasks
Reference - technical details
In this section...