【问题标题】:My database SQL does not allow me to access a hint我的数据库 SQL 不允许我访问提示
【发布时间】:2013-03-20 16:30:43
【问题描述】:

它不允许我从我的数据库中访问我的提示,出现错误。

代码:

def do_question(self):
    self.func1()
    #myGlobal + 1
    if myGlobal >5:
        import MathsvadersReal

    SQL = 'SELECT * FROM tblQuestion'
    cursor = Databaseconnector.SELECT(SQL)
    rows = cursor.fetchall()
    random_row = random.choice(rows)

    print random_row.QuestionID, random_row.Question, random_row.Hint, random_row.A1, random_row.A2, random_row.A3, random_row.A4, random_row.CorrectAnswer

    # create welcome label
    self.label1 = Tkinter.Label(self, bg ='yellow', text = (random_row.Question))
    self.label1.grid(row = 0, column = 6, columnspan = 2, sticky = 'E')

    self.label111 = Tkinter.Label(self, bg ='red', text = (random_row.QuestionID, "."))
    self.label111.grid(row = 0, column = 1, columnspan = 4, sticky = 'W')

提示代码:

def homepage_link(self):
    lbl = self.label111['text']
    SQL = 'SELECT Hint FROM tblQuestion WHERE QuestionID = ' + lbl  + ''
    print SQL
    cursor = Databaseconnector.SELECT(SQL)
    rows = cursor.fetchall()
    #row = rows
    tkMessageBox.showinfo("Hint", (row.Hint))

错误:

ProgrammingError: ('42000', "[42000] [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'QuestionID = 9 .'. (-3100) (SQLExecDirectW)")

【问题讨论】:

    标签: python database user-interface python-2.7 tkinter


    【解决方案1】:

    您从self.label111['text'] 检索的值不是有效整数,您应该删除文本末尾的"."

    self.label111 = Tkinter.Label(self, bg ='red', text=random_row.QuestionID)
    # ...
    SQL = 'SELECT Hint FROM tblQuestion WHERE QuestionID = %s' % self.label111['text']
    

    【讨论】:

    • 我更改了它并得到了一个新错误:AttributeError: 'list' object has no attribute 'Hint'
    • 另一个错误:TypeError:行索引必须是整数,而不是str
    • @SmithJr 那么应该是rows[0][0]。请注意,我无法记住 Python 模块的所有详细信息,因此如果您需要更多信息,我建议您提出一个新问题。
    猜你喜欢
    • 2017-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-01
    • 2012-09-21
    • 1970-01-01
    • 1970-01-01
    • 2019-09-09
    相关资源
    最近更新 更多