I am encountering an error when trying to insert data into a database using pyodbc.
The error is as follows:
('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'Anthony'. (102) (SQLExecDirectW); [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Unclosed quotation mark after the character string ')\n '. (105)")
The code I am currently using is:
msconn=pyodbc.connect(driver='{Test Server}',
server='Test\Test',
database='Test',
trusted_msconnection='yes')
cursor=msconn.cursor()
for index, row in Terms.iterrows():
I1 = 'COLUMNIDENTIFIER'
I2 = row['EID']
I3 = row['Legal Name']
insert_query = """
INSERT INTO Test.Table
VALUES ('{}','{}','{}')
""".format(I1,I2,I3)
cursor.execute(insert_query)
cursor.commit()
cursor.close()
msconn.close()
Checking the source file shows that the cause of the error is a name with an apostrophe. (I3)
Is there a way for me to upload the name with the "'"?
Thanks in advance.