Hello every one, anyone can explain : how to save data from st.experimental_data_editor into sqlite3?

I try to build a simple app for accounting without excel.

Hi @Script_Bash

You can use the given code snippet for creating your app and make the changes according to your need.

import streamlit as st
import sqlite3

#Create a DataFrame 
data = st.experimental_data_editor(key="data_editor")

#Connect to the SQLite database (create it if it doesn't exist)
conn = sqlite3.connect("mydata.db")
cursor = conn.cursor()

#Define a table as per your need
cursor.execute("""
   CREATE TABLE IF NOT EXISTS mytable (
       column1 TEXT,
       column2 INTEGER,
       ...
   )
""")

#insert the values you needed
for index, row in data.iterrows():
   cursor.execute("INSERT INTO mytable (column1, column2, ...) VALUES (?, ?, ...)",
                  (row['column1'], row['column2'], ...))

#Commit the changes and close the database connection
conn.commit()
conn.close()

Also, check the stremlit version you are using. Since, their are changes made in the streamlit update.

If you want to know more about it then visit the link give below:

THANK YOU very much

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.