我正在试着用一种简单的方式阅读 .CSV
将测试结果文件放入我的sql server express数据库中,我可以将25行中的两行放入我的数据库中,但随后它会出错并出现以下错误:
数据错误:('22003',u'[22003][microsoft][odbc sql server driver][sql server]将varchar转换为数据类型numeric时出现算术溢出错误(8115)(sqlexecdirectw)[22003][microsoft][odbc sql server驱动程序][sql server]语句已终止(3621)')
它没有指定引起问题的字段或列;我搜索了google和stackexchange,但是没有找到任何解决这个问题的方法。任何帮助都将不胜感激。
我正在使用python2.7、sqlserverexpress和pyodbc作为两者之间的连接。
下面是我尝试运行的代码:
import pyodbc
import csv
print
print("Please wait while I connect to database...")
print
# Connecting to the Database
mydb = pyodbc.connect('Driver={SQL Server};'
'Server=DESKTOP-5I015MM\SQLEXPRESS;'
'Trusted_Connection=yes;')
# Turning on autocommit
mydb.autocommit = True
# Creating a cursor object
mycursor = mydb.cursor()
mycursor.execute("USE mydatabase")
print
print("Connection to the database was successful!")
# Adding Test Results to database - Look into this...
strSQL='''INSERT INTO TestResults(datasource, modelNumber, testSequence, reportingCondition, testDate, isc, voc, imp, vmp, ff, pmp, noct)
VALUES ('SolarLabs',?,?,?,?,?,?,?,?,?,?,?)'''
# open csv file
with open('test_results_NOCT.csv','rb') as f:
csvfile= csv.reader(f)
next(csvfile)
for row in csvfile:
mycursor.execute(strSQL, row)
print
print("Test Results added successfully")
print
下面是我试图读入sql的csv代码:
Model,Test Sequence,Condition,Date,Isc,Voc,Imp,Vmp,FF,Pmp,NOCT
KUT0012,Baseline,STC,3/11/2008,5.2,44.7,4.88,35.7,75,174.3,51.9
KUT0003,Baseline,STC,3/11/2008,5.34,44.7,5.03,35.7,75.2,179.7,52.1
KUT0003,TC200,STC,5/7/2008,5.2,45.1,4.83,36.4,75.2,176.2,-
KUT0004,Baseline,STC,3/11/2008,5.21,44.8,4.91,36.1,76,177.2,51.8
KUT0004,TC200,STC,5/7/2008,5.17,45.1,4.81,36.5,75.3,175.6,-
KUT0004,Hotspot,STC,6/25/2008,5.09,45.6,4.7,37,74.9,173.7,-
KUT0001,Baseline,STC,3/11/2008,5.32,44.6,4.95,35.4,73.8,175.2,51.8
KUT0001,TC200,STC,5/7/2008,5.2,45,4.77,36.8,75.1,175.6,-
KUT0006,Baseline,STC,3/11/2008,5.35,44.4,4.95,35.8,74.5,177.2,52
KUT0006,UV,STC,6/5/2008,5.28,44.6,4.84,35.8,73.7,173.7,-
KUT0006,TC50,STC,7/4/2008,5.22,45,4.72,36.9,74.1,173.9,-
KUT0006,HF10,STC,8/1/2008,5.21,45.1,4.69,37,73.9,173.4,-
KUT0006,Termination,STC,8/19/2008,5.23,45,4.62,37.3,73.2,172.5,-
KUT0007,Baseline,STC,3/11/2008,5.25,44.4,4.87,35.8,74.6,174.2,52.1
KUT0007,UV,STC,6/5/2008,5.39,43.9,4.84,35.5,72.5,171.7,-
KUT0007,TC50,STC,7/4/2008,5.56,44.7,4.87,36.8,72.2,179.3,-
KUT0007,HF10,STC,8/1/2008,5.5,44.6,4.85,36.4,72.2,176.8,-
KUT0005,Baseline,STC,3/11/2008,5.13,44.3,4.84,35.6,75.7,172.3,51.7
KUT0005,Damp Heat,STC,5/8/2008,5.11,45.5,4.7,37.4,75.4,175.6,-
KUT0005,Static Load,STC,5/29/2008,4.95,45.6,4.67,37.6,77.6,175.5,-
KUT0008,Baseline,STC,3/11/2008,5.13,44.6,4.84,36,76.2,174.4,52.2
KUT0008,Damp Heat,STC,5/8/2008,5.17,44.9,4.78,36.2,74.4,172.7,-
KUT0008,Hail,STC,5/21/2008,5.14,44.5,4.73,35.8,74,169.4,-
KUT0011,Baseline,STC,3/11/2008,5.24,44.7,4.99,35.8,76.1,178.4,51.9
KUT0011,Outdoor Exposure,STC,4/17/2008,5.05,44.3,4.79,35.6,76.4,170.7,-
下面是表模式:
表架构
暂无答案!
目前还没有任何答案,快来回答吧!