I want load data into an MSSQL database from a dataframe OutputDataSet with rows

'FaultTagNo','SparePartNo','AssemblyNo','SupplierID','LogNo','HW_RevIn','HW_RevOut',
'ProblemCode','ProblemDesc','SerialNo','MROc','FW_RevIn','FW_RevOut','DateReceived',
'DateTested','NFF','ClaimedDOA','FaultCode1','FaultFound1','TestStageFailed','Scrapped',
'ScrapCode','SubGeo','Geo','VendorID','MaterialCategory','NITSValue','CREATE_DT'.

I use this code to load data

     cnxn = pyodbc.connect(driver='{SQL Server}',
                          server='IP adress',
                          database='nameDB',
                          uid='me',
                          pwd='pass')

    cursor = cnxn.cursor()

    for index,row in OutputDataSet1.iterrows():
        cursor.execute("INSERT INTO dbo.OMEGA_SPEQ_REPORT,([ID],[FaultTagNo],[SparePartNo],[AssemblyNo],[SupplierID],\
                       [LogNo],[HW_RevIn],[HW_RevOut],[ProblemCode],[ProblemDesc],[SerialNo],[MROc],[FW_RevIn],\
                       [FW_RevOut],[DateReceived],[DateTested],[NFF],[ClaimedDOA],[FaultCode1],[FaultFound1],\
                       [TestStageFailed],[Scrapped],[ScrapCode],[SubGeo],[Geo],[VendorID],[MaterialCategory],\
                       [NITSValue],[CREATE_DT]), values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
                        row['ID'],row['FaultTagNo'],row['SparePartNo'],row['AssemblyNo'],row['SupplierID'],row['LogNo'],
                         row['HW_RevIn'],row['HW_RevOut'],row['ProblemCode'],row['ProblemDesc'],row['SerialNo'],row['MROc'],
                         row['FW_RevIn'],row['FW_RevOut'],row['DateReceived'],row['DateTested'],row['NFF'],
                         row['ClaimedDOA'],row['FaultCode1'],row['FaultFound1'],row['TestStageFailed'],row['Scrapped'],
                         row['ScrapCode'],row['SubGeo'],row['Geo'],row['VendorID'],row['MaterialCategory'],row['NITSValue'],


row['CREATE_DT'])
    cnxn.commit()
    cursor.close()
    cnxn.close()

And it shows me an error

File "<input>", line 20, in <module> 
pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near ','. (102) (SQLExecDirectW); [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared. (8180)")

I just can't see the mistake. Line 20 is the last in cursor.execute() = row['CREATE_DT'])

0 Answers