"update financeinfo set monthoftheyear='%s','Grossincome='%d', where ID='%s'"%(monthoftheyear,Monthlyincome,Grossincome,ID))
时间: 2023-08-01 15:06:00 浏览: 48
在你的代码中,你在 `update` 语句中的 `monthoftheyear='%s'` 和 `Grossincome='%d'` 两个部分都缺少一个引号,应该改为 `monthoftheyear='%s',` 和 `Grossincome='%d',`。另外,你在 `Grossincome='%d',` 中传入了 `Grossincome` 变量,但实际上这个变量应该是 `Monthlyincome`。因此,正确的代码应该是:
```
conn.execute("update financeinfo set monthoftheyear='%s', Grossincome='%d' where ID='%s'" % (monthoftheyear, Monthlyincome, ID))
```
当然,我建议你使用参数化查询来避免这种错误。例如:
```
conn.execute("update financeinfo set monthoftheyear=?, Grossincome=? where ID=?", (monthoftheyear, Monthlyincome, ID))
```
相关问题
conn.execute("update financeinfo set monthoftheyear='%s',Grossincome='%d', where ID='%s'"%(monthoftheyear,Monthlyincome,Grossincome,ID)) TypeError: not all arguments converted during string formatting
这错误通常是由于字符串格式化时格式化字符串中的占位符与传入的参数数量或类型不匹配导致的。在你的代码中,可能是因为你在 `Grossincome='%d',` 语句中漏掉了一个参数,应该是 `Grossincome='%d',具体看一下你的代码,看看有没有传入足够的参数或者参数类型是否正确。另外,你也可以考虑使用参数化查询来避免这种错误。例如:
```
conn.execute("update financeinfo set monthoftheyear=?, Grossincome=? where ID=?", (monthoftheyear, Monthlyincome, ID))
```
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)