The code ran without any errors; however, I encountered an issue where the data did not update in the MS Access database table using Python. It displayed the correct data after executing the connection commit command, but when I reopened the app, it showed the previous data without any updates. Could you please take a look at my code and provide your best guidance on how to properly save data in the MS Access table? Thank you in advance for your assistance!
import streamlit as st
import pyodbc
import pandas as pd
conn_str = (
râDRIVER={Microsoft Access Driver (*.mdb, *.accdb)};â
râDBQ=C:\iqra\mfa.accdb;â
)
connm = pyodbc.connect(conn_str)
cursorm = connm.cursor()
query = âSELECT * FROM Paymentsâ
dataf = pd.read_sql(query, connm)
print(dataf)
i_want_to_multiply = 2
filtered_rows = dataf.loc[dataf[âPayment_IDâ] == 20]
filtered_rows[âGross_Payâ] = 100
print(filtered_rows)
sql = âââUPDATE Payments SET [Gross_Pay]=? WHERE [Payment_ID]=? âââ
for index, row in filtered_rows.iterrows():
print([row[âGross_Payâ], row[âPayment_IDâ]])
cursorm.execute(sql, [row[âGross_Payâ], row[âPayment_IDâ]])
cursorm.commit
connm.commit
query = âSELECT * FROM Paymentsâ
dataf = pd.read_sql(query, connm)
print(dataf) # give update data or
cursorm.close()
connm.close()