Bajram_MA
Bajram_MA

Reputation: 21

pyodbc import error because of Invalid Datetime format

I´ve already look it up here, but couldn´t find a solution for my problem. I want to get a dataframe from 4 accces databanks and 2 work with this exact code and the other 2 display this error:

DataError: ('22007', '[22007] [Microsoft][ODBC-Treiber für Microsoft Access]Ungültiges Datetime-Format. bei Spaltennummer 11 (dtime) (35) (SQLGetData)')

the Data is in each data bank the same in terms of format. See my code below:

    conn_str = (
r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};'
r'DBQ=C:\Users\hoho11.DE\Documents\WLTP_Datenbank\Database_JRC2_SE_UK.accdb;')

conn = pyodbc.connect(conn_str)

cursor = conn.cursor()

for table_info in cursor.tables(tableType='TABLE'):
    print(table_info.table_name)

and the error comes here:

df_3 = pd.read_sql_query(sql='SELECT * FROM TB_cycles_car', con=conn)
df_3.head()

many thanks in advance for your support!!

Upvotes: 1

Views: 675

Answers (1)

Bajram_MA
Bajram_MA

Reputation: 21

So I finally find the answer. I selected the Error showing column and import it as a string. I just wrote:

df = pd.read_sql_query(sql='SELECT ID, ..., Cstr(dtime), dates FROM TB_cycles_car', con=conn)

The DataError didn´t show up anymore :) Thanks a lot @GordThompson for helping!

Upvotes: 1

Related Questions