I am importing csv file to SQL server, my csv file consists of columns with null values.. here is my snippet,
@event.listens_for(engine, 'before_cursor_execute')
def receive_before_cursor_execute(conn, cursor, statement, params, context, executemany):
if executemany:
cursor.fast_executemany = True
for filename in os.listdir(directory):
df = pd.read_csv(fl_path,header=0, dtype=str)
df.fillna("", inplace=True)
df.to_sql(table_name, con=engine, if_exists='append', index=False)
I got the following error,
sqlalchemy.exc.DataError: (pyodbc.DataError) ('22018', '[22018] [Microsoft][ODBC Driver 17 for SQL Server]Invalid character value for cast specification (0) (SQLExecute)')
when I try to convert null into blank, I'm getting error and I want to insert null values as blank.. and when i insert null as null into database I'm not facing any errors.. please help me where I'm going wrong