关于基于Access表的for循环的问题

时间:2016-04-01 16:42:24

标签: python sql

本质上应该发生的是从数据库表中获取包含ID的一些信息。如果在数据库中找到一个input.text()元素作为其中一个ID,我希望它运行X,而是绕过并运行Y

`DBConnect = pyodbc.connect('Driver={Microsoft Access Driver (*.mdb, *.accdb)}; Dbq=C:\\A\\B\\C;')
    DBSelect = DBConnect.cursor()
    DBSelect.execute("select * from ...)
    Row = DBSelect.fetchall()
    Update = False
    for field in Row:
        Appointment_ID = field[0]
        print(Appointment_ID)
        Selected_ID = self.ui.input.text()
        Selected_ID = str(Selected_ID)
        print(Selected_ID, "this is selected")
        print(Update)

        if Appointment_ID == Selected_ID:
            Update = True

    print(Update, "this is update")
    if Update == True: 
        run X
    else:
        run Y`

这里是我输入141时运行此代码时产生的打印输出,正如您所看到的那样,它不会产生Update = True输出

139 141这是选中的, 假, 140, 141这是选中的, 假, 141, 141这是选中的, 假, 这是更新

1 个答案:

答案 0 :(得分:0)

你有一个错误。在循环中

更新== True应为Update = True
相关问题