Setting Up a Database Input

In another help file - Setting up the database connection on your PC - we explain how to set up a database on your PC via the Windows ODBC set up. In the following, we show you how to import and export data from databases in Simul8.

Setting up your SQL Connection in Simul8

Database query setup:

  • Go into “Data and Rules” on the top panel.
  • In “External Data Sources”, choose the SQL option.
  • The SQL database connection menu opens automatically and shows any existing SQL connections or is blank if this is the first connection.
  • Choose “New” to establish a new database connection.

Database connection wizard

  • In the wizard:
    • Choose the database as it is named in the ODBC set up.
    • Enter the table as name in the database. Here we use the “Orders” table.
    • Choose the internal spreadsheet in Simul8, either to which to import the data or from which to export it. You can also create a new spreadsheet for importing from here.
    • Choose whether to import or export your data.

For importing:

Database connection for importing data

  • Choose whether to “Import All” or “Custom”. The first option imports the whole data table while the second option allows for importing only part of the data according to some rules as shown next.
  • In the “Custom” option, you can use the “SQL Editor” to choose which part of the data to import. As an example, in the “Orders” table we only import the data items that have a value of 3 in the “lblProductID” column.

SQL Editor to import subsets of the data table

  • In the “SELECT” window we specify which columns to import - if we want to import all columns, we use the “*”.
  • In “WHERE”, we then set up which data items (row-wise) to import. Here, we only import these with a value of 3 in “lblProductID”.
  • The command as shown below can be used for the same result.

Example of an SQL query command

  • After clicking “OK” for all the dialogs, the SQL database connection menu now includes the previously set up connection.

Existing connection in SQL database menu

  • You can now use the “Import/Export” button to import the data into an internal spreadsheet. The connection can also be modified from here via “Properties”.

For exporting:

Database connection for exporting data

  • Choose whether to insert the export into a database or update a database. The first exports the data by adding it into the first blank row after any existing entries. The second option updates existing entries by overwriting these.
  • When clicking “OK”, the connection is shown in the database connection menu and data can be exported via the “Import/Export” button while it can be modified via “Properties”.

Visual logic commands for importing/exporting databases

In addition to the above, you can also read, write, insert or delete records in your database you use SQL commands through Visual Logic. The Visual Logic SQL commands available are: