title: Inserting Names with apostrophe to a Database Table using Python
body: <p>I am encountering an error when trying to insert data into a database using pyodbc. </p>
  
  <p>The error is as follows:</p>
  
  <blockquote>
    <p>('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)")</p>
  </blockquote>
  
  <p>The code I am currently using is:</p>
  
  <pre><code>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()
  </code></pre>
  
  <p>Checking the source file shows that the cause of the error is a name with an apostrophe. (I3)</p>
  
  <p>Is there a way for me to upload the name with the "'"?</p>
  
  <p>Thanks in advance.</p>