永发信息网

python 如何把变量的值传递给execute的sql中去

答案:1  悬赏:80  手机版
解决时间 2021-11-13 03:29
  • 提问者网友:眉目添风霜
  • 2021-11-12 18:12
python 如何把变量的值传递给execute的sql中去
最佳答案
  • 五星知识达人网友:过活
  • 2021-11-12 19:16
问题:
curs.execute("select * from tables where userid=%s and code=%s")%(IDEntry2.get(),%IDEntry1.get()) #Entry获取的值无法当成变量传递给execute的sql语句中。

问题是IDEntry1之前多了一个%

解决:
#curs.execute("select * from tables where userid=‘aaa’ and code=‘123’") //直接写死就可以
按照可以的进行替换
selectSql = "select * from tables where userid=‘%s’ and code=‘%s’" % (str(IDEntry2.get()),str(IDEntry1.get()))#加str确认与%s匹配
curs.execute(selectSql)
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯