我正在编写一些简单的
Python代码来从CSV文件中提取数据并将其发送到sql Server数据库.但我得到这个07002 COUNT字段不正确或语法错误. CSV文件有多个值,如果我只发送一行数据,则插入正常.问题在于CSV文件中有多个值.任何帮助表示赞赏!
这是我的代码:
import_data = [] for csvFile in glob.glob("*.csv"): with open(csvFile,'r') as f: reader = csv.reader(f)<br> next(reader,None)#This skips the headers. import_data = [tuple(line) for line in csv.reader(f)]
cur.executemany("""INSERT INTO dbo.currentobservations(STID,NAME,ST,LAT,LON,YR,MO,DA,HR,MI,TAIR,TDEW,RELH,CHIL,HEAT,WDIR,WSPD,WMAX,PRES,TMAX,TMIN,RAIN) VALUES (?,?,?)""",import_data) #Here is the error message I am getting: Traceback (most recent call last): File "E:\Python3\Programs\sqlservermesonetcsv.py",line 40,in <module> cur.executemany("""INSERT INTO dbo.currentobservations(STID,import_data) File "E:\Python3\lib\site-packages\pypyodbc.py",line 1671,in executemany self.execute(query_string,params,many_mode = True) File "E:\Python3\lib\site-packages\pypyodbc.py",line 1605,in execute self.execdirect(query_string) File "E:\Python3\lib\site-packages\pypyodbc.py",line 1631,in execdirect check_success(self,ret) File "E:\Python3\lib\site-packages\pypyodbc.py",line 986,in check_success ctrl_err(sql_HANDLE_STMT,ODBC_obj.stmt_h,ret,ODBC_obj.ansi) File "E:\Python3\lib\site-packages\pypyodbc.py",line 966,in ctrl_err raise DatabaseError(state,err_text) pypyodbc.DatabaseError: ('07002','[07002] [Microsoft][ODBC sql Server Driver]COUNT field incorrect or Syntax error')