Click here to Skip to main content
15,885,878 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
While I am trying to insert a row to my table from the Tkinter Entry widget, I'm getting the following errors:

Python
Due to failed processing format-processing; Python "StringVar" cannot be converted to a MySQL type. 


This is our code so far :

Python
conn = mysql.connector.connect(host="localhost", username="root", password="Try#$12", database="attendancesystem")
c = conn.cursor()
params =  (crsVar.get(), sbVar.get(), yrsVar.get(), smVar.get(),
            nVar.get(), rollVar, genVar.get(), dVar.get(),
            eVar.get(), mobVar.get(), adVar.get(), rdVar.get())
                          )

sql_insert_query = '''INSERT INTO `students_detail`
                        (Course, Subject, Year, Semester, Name, Roll_No, Gender, DOB, Email, Mobile, add, Photo) 
                VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)'''

c.execute(sql_insert_query, params)

conn.commit()
conn.close()


It should take input from the Tkinter (Entry, Combobox and radio button) form and insert it into the database the Columns of the Table ( Course, Subject, Year, Semester, Name, Roll No, Gender, DOB, Email, Mobile, add, Photo )
And all the text variables for tkinter widgets are StringVar().
Please help me out.

What I have tried:

I tried different methods to solve this by seeing similar questions on StackOverflow or GitHub and by reading Documentation
Posted
Updated 8-Jul-21 2:56am
Comments
Richard MacCutchan 8-Jul-21 8:58am    
Please show the complete schema of the students_detail table.

1 solution

Quote:
Python
params =  (crsVar.get(), sbVar.get(), yrsVar.get(), smVar.get(),
            nVar.get(), rollVar, genVar.get(), dVar.get(),
            eVar.get(), mobVar.get(), adVar.get(), rdVar.get())
)
Based on the variable name and the surrounding code, I suspect you're missing the .get() from your rollVar.
Python
params =  (crsVar.get(), sbVar.get(), yrsVar.get(), smVar.get(),
            nVar.get(), rollVar.get(), genVar.get(), dVar.get(),
            eVar.get(), mobVar.get(), adVar.get(), rdVar.get())
                          )
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900