我想从具有行的数据框OutputDataSet将数据加载到MSSQL数据库中
'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'.
我使用此代码加载数据
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()
它显示了一个错误
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)")
我只是看不到错误。
第20行是cursor.execute() = row['CREATE_DT'])