bruhbruh
bruhbruh

Reputation: 27

Cant display items from database to listbox

My program uses sqlite3 and tkinter, and I am currently trying to display the first and surnames of users in a class when I search for it. However, rather than display the names of each user, I get a 0 for each user in the class. I am not sure how to get it to display the names instead, although in the "for item in stud_name...." part of the code it is seeing the results as a list of sorts and displaying each result as it would be a value from a list.

        ClassnameEdit = (editclassname.get())
        conn = sqlite3.connect('MyComputerScience.db')
        c = conn.cursor()
        c.execute("SELECT * FROM ClassInfo WHERE ClassName = ?", (ClassnameEdit,))
        search_class_results = c.fetchall()
        print (ClassnameEdit)
        if len(search_class_results) == 0:
            user_searchresult.insert(END, "No class found!")
        else:
            stud_name_class = c.execute("SELECT FName AND SName FROM users WHERE ClassName = ?", (ClassnameEdit,))
            stud_name_classr = stud_name_class.fetchall()
            for item in stud_name_classr:
                user_searchresult.insert(END, item)

Upvotes: 0

Views: 27

Answers (1)

forpas
forpas

Reputation: 164184

The concatenation operator for SQLite is || and not AND.
Change to this:

SELECT FName || ' ' || SName FROM users WHERE ClassName = ? 

Upvotes: 1

Related Questions