Hello and welcome to a new guide on how to best use Movicon.NExT™.
In this technote, we are going to show you how to connect to a database table and display the data within Combobox so that it can be selected and shown on screen.
Example
Movicon.NExT offers several graphical objects, and a driver, that allows you to connect to a database and perform queries.
To give you a clearer picture of how this is done we will use an example.
How to create the tag
We shall now define an Int16 type tag to connect to the PLC simulator. To do this:
Open the I/O Data Server located in the project tree in the Project Explorer window.
Access the Tags List by selecting the corresponding I/O Data Server’s tab.
Right-click on the workspace and select the Add New Tag option from the menu that opens.
Configure the tag by using its properties window in the following way:
Name
CBSelItem
Model Type
Variable
Data Type
String
Click on the Accept Changes button on the tag’s properties window to toolbar.
Now that you have finished configuring the tag, save the project by clicking on the Save All button on the Movicon.NExT Editor’s toolbar at the top.
How to create the screen
Now, we will need to create a screen:
Look for the Screens resource in the Project Explorer window’s tree structure and select it.
Right-click it and select the New option from the menu which opens.
A New Screen popup will appear through which you can set the screen's main properties. Configure the screen as follows:
Width:
1920
Height:
1080
Name:
Main
Click the OK button to confirm the configuration.
Once the screen has been created, you can then change the project's properties by inserting the screen as the project's Main screen which will show when the project starts up. To do this:
Select the name of the project from the application's tree structure.
Open the Properties window.
Change the following project properties in this way:
Startup Page Type: Main Screen
Startup Screen Name: Main
Once you have finished configuring the project startup page, click on the Save All icon located on the toolbar at the top to save the project.
Now, open the Main screen and click on the Toolbox tab, which is located on the far right of the editor window, next to the properties window, to open the Toolbox library provided by Movicon.NExT.
Go to the Dialog Box folder and select and drag the ComboBox object onto the screen. Select and drag the CBSelItem tag onto the object to assign it.
Now, we shall configure the data source to use with the ComboBox. In this example, we shall use the SQL Server’s Northwind sample database provided by Microsoft.
To do this:
Select the ComboBox that you previously placed on the screen and open the Object Settings section in its Properties Window.
In this section, go to the Source Reader Settings and click on the three dotted button on its right to open the database connection string configuration wizard.
When the popup opens, click on the three dotted button corresponding to the Connection property. This will open another popup through which you can build the connection string.
Select the Microsoft SQL Server as the Data Provider. Click OK to confirm.
Once the provider has been selected, insert the database instance name in the Server Name combobox. If you wish to use SQL Express with named instance, insert the (local)\SQLEXPRESS string.
Select either Window authentication or SQL Server authentication as the authentication type you wish to use.
Select the database from the Select ComboBox or enter it manually. In this example we shall use Northwind.
Click the Test Connection button to verify that the database connection is the correct one and then click OK to confirm.
Once the connection string has been created, you can now go ahead and connect the ComboBox to the data you wish to display. To do this:
Click the three dotted button on the far right of the Select property.
Search for the table you wish to access in the popup that appears. In this example, this will be [dbo].[Region]. This is a simple table with a two column and four row layout.
After selecting the table, select the column you wish to display at runtime. In this example, this will be the [RegionDescription] column and click OK to confirm.
Click the OK button once again to confirm the configuration.
Save the project by clicking on the Save All button on the Movicon.NExT Editor’s toolbar at the top.
Runtime Test
Now test everything in runtime mode by clicking the Start Runtime icon.
Once the screen has loaded, you should see the ComboBox showing the Eastern value on screen.
When you click on this graphical object, a list will appear with the selected column’s values. When you select one of these, the value will be obtained from the CBSelItem tag.