I try to load pandas dataframe to SQL Server. The dataframe has following columns:
- userId - int
- saleId - int
- regTime - int
- countryId - int
cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
cursor = cnxn.cursor()
for index, row in users.iterrows():
cursor.execute('INSERT INTO [dbo].[users]([userId],[saleId],[regTime],[countryId]) values (?,?,?,?)',
row['userId'],
row['saleId'],
row['regTime'],
row['countryId'])
cnxn.commit()
cursor.close()
cnxn.close()
But i have the following error:
---------------------------------------------------------------------------
ProgrammingError Traceback (most recent call last)
<ipython-input-103-383c1873cad8> in <module>
4 row['saleId'],
5 row['regTime'],
----> 6 row['countryId'])
7 cnxn.commit()
8 cursor.close()
ProgrammingError: ('Invalid parameter type. param-index=0 param-type=numpy.int64', 'HY105')
countryId column has values from 0 to 9 (codes)
How can i correct it?