简体   繁体   English

参数必须是 str 而不是元组

[英]Argument must be str not tuple

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)结果 = conn.execute(内容)

TypeError: argument 1 must be str, not tuple类型错误:参数 1 必须是 str,而不是元组

any possible solution?任何可能的解决方案?

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM