通过python

时间:2017-03-24 11:08:23

标签: python sqlite

我有两个列表列[],rows []。我试图在名为docs的表中插入记录。 表格文档中的列为:(('suggestedpa', None), ('loadid', None ))

CODE

 conn.execute('INSERT INTO docs ('+str(columns)+') VALUES ('+str(rows)+')')

错误 sqlite3.OperationalError: table docs has no column named 'suggestedpa', 'loadid'

1 个答案:

答案 0 :(得分:1)

一种方法是:

columns=['suggestedpa', 'loadid']
rows=['U.S. Bank National Association Intellectual Ventures II LLC', '233996'] 
columnsHelp = map(str,columns)
columnsStr = ",".join(columnsHelp) # this is now a string
rowsHelp = map(str,rows)
#rowsStr = ",".join(rowsHelp) # this is now a string val1,value
# do this 
rowsStr = "'" + "','".join(map(str, rowsHelp)) + "'"
conn.execute("INSERT INTO docs ("+columnsStr+") VALUES ("+rowsStr+")")
祝你好运

相关问题