when i try to load the data from SQL table to popup calendar and checkbox error is occurring.
error below is for checkbox:-
Traceback (most recent call last):
File "<event:mouseClicked>", line 13, in <module>
TypeError: can't convert u'Male' to boolean
Ignition v8.1.28 (b2023060110)
Java: Azul Systems, Inc. 11.0.18
Error below is for Popup calender:-
Traceback (most recent call last):
File "<event:actionPerformed>", line 33, in <module>
TypeError: can't convert u'21-Aug-2001' to java.util.Date
Ignition v8.1.28 (b2023060110)
Java: Azul Systems, Inc. 11.0.18
The error is occurring because of datatype mismatches between unicode strings and boolean/date formats. Can we see the code that is causing the error? I don't know what is being done in line 13 of your mouseClicked event or line 33 of your actionPerformed event that would be causing this issue.
I've created the student registration form and this is the code for edit button. I've to take the data from SQL to retrieve the data into ignition dashboard. I have used separate check box for male and female and popup calendar for date of birth but only male\female check box data and popup calendar dob data is not get loaded into the dashboard from SQL table and other data get retrieved.
table = event.source.parent.getComponent('formtable')
Data = table.data.getValueAt(table.selectedRow, "StudentName")
event.source.parent.getComponent('SName').text = Data
Data1 = table.data.getValueAt(table.selectedRow, "FatherName")
event.source.parent.getComponent('FName').text = Data1
Data2 = table.data.getValueAt(table.selectedRow, "DOB")
event.source.parent.getComponent('DOB').text = Data2
Data3 = table.data.getValueAt(table.selectedRow, "Gender")
event.source.parent.getComponent('fcheck').selected = Data3
event.source.parent.getComponent('mcheck').selected = Data3
Data4 = table.data.getValueAt(table.selectedRow, "Course")
event.source.parent.getComponent('CA').selectedStringValue = Data4
Data5 = table.data.getValueAt(table.selectedRow, "MobileNumber")
event.source.parent.getComponent('MOB').value = Data5
Data6 = table.data.getValueAt(table.selectedRow, "EmailID")
EID = event.source.parent.getComponent('E_ID').text = Data6
Data7 = table.data.getValueAt(table.selectedRow, "Address")
add = event.source.parent.getComponent('Add').text = Data7
Data8 = table.data.getValueAt(table.selectedRow, "SubmittedBy")
SubBy = event.source.parent.getComponent('SubBy').text = Data8
Data9 = table.data.getValueAt(table.selectedRow, "ID")
sno = event.source.parent.getComponent('sno').value = Data9
system.gui.messageBox('Data Successfully Retrieved')
your gender variable Data3
is a string, and the selected property of your checkbox expects a bool. To correct the error, you are going to have to test the string to see if the gender is male or female. Change your code to something like this:
Data3 = table.data.getValueAt(table.selectedRow, "Gender")
isMale = True if Data3 == 'Male' else False
isFemale = True if not isMale else False
event.source.parent.getComponent('mcheck').selected = isMale
event.source.parent.getComponent('fcheck').selected = isFemale
I'm not sure about the date error. It should be loading into your dataset as a date, not as a string. Is datatype in your database a date?
This is never going to do what you want it to.
I expect this should be a boolean, something along the lines of
is_male = table.data.getValueAt(table.selectedRow, "Gender") == "Male"
event.source.parent.getComponent('fcheck').selected = not is_male
event.source.parent.getComponent('mcheck').selected = is_male
I don't see anything about dates though.
Is this the WHOLE script ?
edit: Oh wait, is "DOB" for "date of birth" ?
try this:
event.source.parent.getComponent('DOB').text = system.date.parse(Data2, "DD-MMM-yyyy")
Or do what Justin says below, I don't know the vision calendar component :X
And please, for the sake of whoever has to maintain this: Give proper names to your variables.
1 Like
Is this your popup calendar? If so, try changing the .text
to .date
Yes.
We have taken the dob datatype as varchar in SQL table and in dashboard we have taken popup calendar in dd-MMM-yyyy format. Dob is get loaded into SQL table from dashboard but not get retrieved.
. date is showing error which I've mentioned previously.
Can you alter the table and fix this? Dates should probably not be strings.
If not, combine Pascal's solution with mine, and code it this way:
event.source.parent.getComponent('DOB').date = system.date.parse(Data2, "dd-MMM-yyyy")
Thanks. the code is working properly.
I also 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
In addition to the doc Justin suggested, I recommend learning python/programing basics.
It seems you're expecting parts of your query string to take the values of variables. This is not how it works.
In a string only situation (NOT WITH QUERIES), you'd do this with string formatting. There are multiple ways of doing this in python:
some_value = 42
some_string = "this is a string that shows the value of a variable: {}".format(some_value)
some_other_string = "You could also do it like this : %d" % (some_value)
BUT, in the context of queries, you don't do this, because it opens the query to injection.
So, you either use runPrepQuery
or named queries. Read up on those.
Thanks!!
Now I want to display my different vision windows into the vision client. I am using tab strip for this purpose in docked window. I set the tab strip vertically and then open my project in ignition client but the alignment is not that what i want.
I'm getting this kind of view,
but i want this.
Can you help me with this??
I just completed a tutorial on this here:
Creating Tabs in Vision Client
1 Like