Pyodbc : Sqlexecdirectw Error While Insert
For some reason, I am storing the below array completely in the SQL server using pyodbc in the form of text with single quotes. ['Sachin', 'Yuvraj'] I am inserting the above valu
Solution 1:
This is another example of why using string formatting to embed data values into SQL command text is a bad idea. In this case the rendered string literal creates a syntax error because the single quotes are not properly escaped.
>>>arr = ['Sachin', 'Yuvraj']>>>"... VALUES ('{}')".format(arr)
"... VALUES ('['Sachin', 'Yuvraj']')"
Instead, you should be using a proper parameterized query
sql = """\
INSERT INTO Test_Table (test_name) VALUES (?)
"""tes_table = SQLCURSOR.execute(sql, str(arr))
Post a Comment for "Pyodbc : Sqlexecdirectw Error While Insert"