gpt4 book ai didi

Python MySql Select 语句。来自Python 条目的Where 列

转载 作者:行者123 更新时间:2023-11-29 16:24:11 25 4
gpt4 key购买 nike

我无法弄清楚我已经尝试了很多可能性。我想从数据库中选择一条记录。我从条目中取出一个 txt 并将其放入 select 语句中。

def callback():
txt = rentry2.get()
print("If empty there should be nothing ---> " + txt)
if txt != "":
print("is not empty: " + txt)
my_cursor.execute("SELECT Name, Discription, Quantity, Price, Barcode FROM stock WHERE Barcode='" + txt + "'")
result = my_cursor.fetchall()
for row in result:
rlbl1 = Label(root, text=row)
rlbl1.grid(row=3)
print(row)

我也尝试过使用这个选择语句:

my_cursor.execute("SELECT Name, Discription, Quantity, Price, Barcode FROM stock WHERE Barcode=%s", (txt,))
my_cursor.execute("SELECT Name, Discription, Quantity, Price, Barcode FROM stock WHERE Barcode='%s'", (txt,))

txt 的值是一个条形码:20083335。我从 Tkinter 输入框中获取 txt 值。当我运行代码并将条形码放入输入框中时。它给了我输入框的值,但我没有从 sql 查询中得到任何结果。如果我在 select 语句中输入条形码,我会得到正确的 sql 查询,并且两者都没有任何结果。有人可以帮我吗?错误:mysql.connector.errors.ProgrammingError: 1064 (42000): 您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,了解在第 1 行“20083335”附近使用的正确语法

最佳答案

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '20083335''' at line 1

您可以尝试通过此附加您的txt

my_cursor.execute("SELECT Name, Discription, Quantity, Price, Barcode FROM stock WHERE Barcode=%s",(txt,))

另外您能否仔细检查一下您的“描述”(Description) 列名称是否真的是这样拼写的?可能是拼写错误。

关于Python MySql Select 语句。来自Python 条目的Where 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54352869/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com