Reputation: 359
I have two list columns[],rows[]. I am trying to insert records in a table called docs.
Columns in the table docs are : (('suggestedpa', None), ('loadid', None ))
CODE
conn.execute('INSERT INTO docs ('+str(columns)+') VALUES ('+str(rows)+')')
Error
sqlite3.OperationalError: table docs has no column named 'suggestedpa', 'loadid'
Upvotes: 1
Views: 74
Reputation: 1098
One way to do is :
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+")")
Good luck
Upvotes: 1