为什么我得到这个python MS sql server错误?



当尝试从pandas数据框架写入MS sql server时,我一直得到下面相同的错误。我已经三次检查了所有的数据是否与表上的数据类型匹配。

样本数据:

<表类>POSTING_DATE源READTYPEPPTAGIDETAGID_PLATEEQUIPID机构ENTRY_PLAZAENTRY_DATEEXIT_PLAZAEXIT_DATETOLL_CLASS英里TOLL_AMOUNTIDtbody><<tr>2022-06-06就是精英转发器777777777111111111115363KTA东部入口2022-06-04 17:52:39南部入口2022-06-04 21:50:2550.0031.951111111111111111111112022-06-06就是EZPass转发器777777777111111111115363DelDOT南南D952022-06-03 03:08:2150.009.001111111111111111111112022-06-06就是EZPass转发器777777777111111111115363NJTP12022-06-03 03:27:3822022-06-03 03:39:5650.004.601111111111111111111112022-06-06就是精英转发器777777777111111111115362KTA威奇托:i - 135 i - 235 47圣道明> 2022-06-04 15:21:21南部入口2022-06-04 15:47:5750.005.051111111111111111111112022-06-06就是精英转发器777777777111111111115357OTAWR-BGCBN2022-06-05 02:05:25WR-STLINE2022-06-05 02:38:1750.009.201111111111111111111112022-06-06就是精英转发器777777777111111111115355OTAHEB-NWCLML2022-06-03 07:10:36HEB-NWCLML2022-06-03 07:10:3650.003.95111111111111111111111

需要单独指定每个列,如row[1],row[2]row[15]nora loop

,直接使用executemany(对于DML操作,它也比execute性能更高),例如

import pyodbc
import pandas as pd
con = pyodbc.connect(
"DRIVER=ODBC Driver xx for SQL Server;"
"SERVER=<IP>,<some number>;"
"DATABASE=DB123;"
"Trusted_Connection=yes;"
)

data = pd.read_csv(pathToFile,delimiter= ';') # is just a sample delimiter representation, you should replace with yours 
df = data.values.tolist()
MsExe=con.cursor()
try:
MsExe.fast_executemany = True
MsExe.executemany("""
INSERT INTO test_tolls_table_temp (PostingDate, Source, ReadType, PPTagID, ETagID_Plate, EquipID, Agency, Entry_Plaza, Entry_Date, Exit_Plaza, Exit_Date, Toll_Class, Miles, Toll_Amount, ID)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""",df)
except Exception as exception:
print(exception)
MsExe.close()
con.commit()
con.close();

相关内容

  • 没有找到相关文章

最新更新