【问题标题】:Inserting and reading data within a database在数据库中插入和读取数据
【发布时间】:2016-03-29 12:47:26
【问题描述】:

基本上我试图将数据插入数据库,然后在其他地方读取该数据并将每个单独的片段插入到输入字段中。

首先,这是我希望将数据从Statistics page插入数据库的页面

从这个页面,我希望将职业、月租、估计财产价值全部存储在名为“PropertyStatistics”which is showed here的数据库中

保存后,我希望将存储的值输出到带框的条目中,以便可见

当前代码 我将数据插入数据库的代码:

def data_entry():
        OccupationA = str(Statusvar.get())
        MonthlyRentalA = RentalmoneyUpdated
        EstimatedPropertyValueA = EstimatedValueentry
        PropertyStatisticsR = c.fetchall()
        for column in PropertyStatisticsR:
            ID = column[1]
            OccupationA = column[2]
            MonthlyRentalA = column[3]
            EstimatedPropertyValueA = column[4]


            c.execute("INSERT INTO PropertyStatistics(ID,Occupation,Monthly Rental,Estimated Property Value) VALUES (%s, %s, %s, %s)",
            (ID,OccupationA,MonthlyRentalA,EstimatedPropertyValueA))


            conn.commit()
            time.sleep(1)

函数“data_entry”由“保存”按钮调用,如链接1所示 目前对于此代码,在执行此函数时没有出现错误,但是没有任何内容保存到数据库中,这意味着我忽略了一个错误

我是一个初学者,任何帮助将不胜感激,因为我以前没有做过这种事情。

我不希望回复包含此工作所需的所有代码。我只需要一个小方向,从我现在的位置去哪里

【问题讨论】:

    标签: python mysql database sqlite


    【解决方案1】:

    对于多字的列名,引用时,应该用``.

    INSERT INTO PropertyStatistics(ID,Occupation,`Monthly Rental`,`Estimated Property Value`) VALUES (%s, %s, %s, %s)
    

    【讨论】:

      猜你喜欢
      • 2011-05-12
      • 1970-01-01
      • 1970-01-01
      • 2017-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多