Argument must be str not tuple

401 Views Asked by At

i need to load only the data from database by todays date. date column in database is in TEXT... ''code to load all the data from database''

def load_database(self):
            today_date = current_date[0:11]
            while self.workingpatient_table.rowCount() > 0:
                    self.workingpatient_table.removeRow(0)
            conn = sqlite3.connect(r'mylab.db')
            content = ("SELECT * FROM daily_patients where date=?",(today_date))
            result = conn.execute(content)
            for row_index,row_data in enumerate(result):
                    self.workingpatient_table.insertRow(row_index)
                    for column_index,column_data in enumerate(row_data):
                            self.workingpatient_table.setItem(row_index,column_index,QTableWidgetItem(str(column_data)))
    
            conn.close()

''when i run the program i get following error ''

result = conn.execute(content)

TypeError: argument 1 must be str, not tuple

any possible solution?

1

There are 1 best solutions below

14
On

Change your line from

 content = ("SELECT * FROM daily_patients where date=?",(today_date))
 result = conn.execute(content)

to

 content = ("SELECT * FROM daily_patients where date=?",(today_date, ))
 result = conn.execute(*content)