Button wont write to database

Hi, I am trying to get my button to write up the username and password when clicked, I have this code in the onActionPerformed in script. It is not writing to the database and i checked the connection and thats fine so Ive narrowed it down to the code. I copied the exam given by ignition to a point and made a few of my own changes but does not work, does anyone have any suggestions?

areaNum = self.getChild("txtUserUsername").props.text
machineName = self.getChild("txtUserPassword").props.text
system.db.runNamedQuery("LoginInsert", {"machineName":machineName, "areaNumber":areaNum})

Welcome Sean,

Perspective doesn’t have a Client scope, so all scripting runs on the gateway. The runNamedQuery function requires a project name as the first parameter when run in the Gateway scope.

Hello, would you have an example of the syntax?

Hi schenk, I have ran this code but it is still not writing to my database, the “LoginInsert” at the end is the name of my query and isnt in the file path but I added it because I think thats what it says in the example. Any help would be appreciated.

Username = self.getChild("txtUserUsername").props.text
	Password = self.getChild("txtUserPassword").props.text		 
	system.db.runNamedQuery("FYP", "C:/Program Files/Inductive Automation/Ignition/data/projects/FYP/ignition/named-query/LoginInsert", {"Username":Username, "Password":Password})

Is the named query set for Update Query?

image

So paths for the named query aren’t the physical named path on the physical disk but the path in the project.

Try this:

Username = self.getChild("txtUserUsername").props.text
Password = self.getChild("txtUserPassword").props.text		 
system.db.runNamedQuery("FYP", "LoginInsert", {"Username":Username, "Password":Password})

See also what @JordanCClark is saying about it being an update query.

And if you could post a snapshot of the authoring tab so we can all see how you have things setup that would be a big help.

Thanks bschroeder,

I changed my path as shown below and it worked perfectly.
I had my named query set to the “Update Query” also.

Thanks for your help guys.

			# Grab the area number and machine name from the components we added to the window.
	Username = self.getSibling("txtUserUsername").props.text
	Password = self.getSibling("txtUserPassword").props.text		 
	# A call to our Named Query, inserting the two paramters using dictionary syntax.
	#system.db.runNamedQuery("LoginInsert", {"Username":Username, "Password":Password})
	
	system.db.runNamedQuery("FYP", "LoginInsert", {"Username":Username, "Password":Password})
	#C:/Program Files/Inductive Automation/Ignition/data/projects/FYP/ignition/named-query