Select Table From Dropdown List

Hello all,

Quick question. I have a database with multiple tables. In Ignition, I have a dropdown that list each table and I would like to be able to display each database table’s dataset dynamically in an iginition table located underneath the dropdown.

What I would like to do is to bind, say the Dropdown.selectedLabel “Table 1” to the data of my database Table1 and display it below. I would need to repeat this 10 times, to have 10 different dropdown labels that are bound to display 10 different datasets. Is this possible?

I’m using Ignition 7.9 and SQL Server. I have already connected my database to ignition and am pulling data easily. I’m just stumped on the above situation. Any help would be great.

The specifics here would depend on the kind of database you’re using, etc… but the first method for accomplishing this that comes to my mind is:

Set up your dropdown list so that it has two columns in its Data property, “Value” and “Label”, both strings. Populate “Value” with the actual names for your database tables, and “Label” with the names you want to display on your dropdown. Then put a property change script on the dropdown… something like this:

if event.propertyName == "selectedStringValue":
	dbQuery = "SELECT * FROM " + event.source.selectedStringValue
	dbData = system.db.runQuery(dbQuery)
	event.source.parent.getComponent('Table').data = system.dataset.toDataSet(dbData)

You should take a look at the documentation for system.db.runQuery, to make sure that you are using it right. For example, if the db you’re accessing isn’t the default db for this project, then you’ll wnat to enter it in the second parameter.

Also, some SQL servers have different syntaxes from others. Generally, SELECT statements are the same, but you never know, so basically you should tweak the above code to make it work for your specific application.

1 Like

Or just reference the table name in a SQL binding, like so:

FROM {Root Container.Drop Down.selectedStringValue}

It was a combination of your advice and @zacslade’s advice that solved my problem. Thank you both very much! I did take a look at the system.db.runQuery and it helped me understand the logic behind the statements you all provided.

1 Like