Retrieve the data from SQL table to ignition dashboard

I have created a table in SQL and have to retrieve the data from a particular ID column at a time. I've created a numeric textbox named 'sno' in ignition dashboard into which i am putting ID no. and I wish to retrieve the data of that id no. into ignition dashboard, but the error is occurring in my code.

IDS = event.source.parent.getComponent('sno').value
query = ("SELECT StudentName, FatherName, DOB, Gender, Course, MobileNumber, EmailID, Address, SubmittedBy FROM Std WHERE ID = IDS")

error is


Traceback (most recent call last):
  File "<event:actionPerformed>", line 17, in <module>
java.lang.Exception: java.lang.Exception: Error executing system.db.runQuery(SELECT StudentName, FatherName, DOB, Gender, Course, MobileNumber, EmailID, Address, SubmittedBy FROM Std WHERE ID = IDS, , )

caused by Exception: Error executing system.db.runQuery(SELECT StudentName, FatherName, DOB, Gender, Course, MobileNumber, EmailID, Address, SubmittedBy FROM Std WHERE ID = IDS, , )
caused by GatewayException: Invalid column name 'IDS'.
caused by SQLServerException: Invalid column name 'IDS'.


Ignition v8.1.28 (b2023060110)
Java: Azul Systems, Inc. 11.0.18

There is an error with system.db.runQuery so try using system.db.runPrepQuery

The error message is telling you exactly what's wrong:

2 Likes

This needs to be done differently. Search the forum for named query examples, and learn how to pass user inputs as parameters. Appending user inputs to your query strings creates an injection attack vulnerability.

1 Like