Using file uploader and store it in database

Hey,
i’m trying to create somthing that can import info to my database, for example: i have and excel sheet that contains 3 fields (id, name and number), i tried using file uploader to add this sheet to my database but it’s not working, if anyone can help me read this excel into my database.
Code:
def create_etable():
c.execute(‘CREATE TABLE IF NOT EXISTS etable(eid INT,name TEXT,number TEXT)’)

def add_edata(eid,name,number):
c.execute(‘INSERT INTO etable(eid,name,number) VALUES (?,?,?)’,(eid,name,number))
conn.commit()

def view_all_emp():
c.execute(‘SELECT * FROM etable’)
data = c.fetchall()
return data

   upload_file = st.file_uploader("Import Employee File", type="xlsx", key='a_c')
   if upload_file:
                  create_etable()
                  df = pd.read_excel(upload_file)
                  add_edata(upload_file)
                  results = view_all_emp()
                  clean_df = pd.DataFrame(results,columns=["ID","Name","Phone Number"])
                  st.dataframe(clean_df)

Thanks,
RED

This cannot work:

df = pd.read_excel(upload_file)
add_edata(upload_file)

Your read df and never use it again?
You pass a file descriptor to a function which expects 3 values?

hello,
thank you for your reply it’s really appreciated,
can you please help me out to fix it? I am still a beginner in streamlit
Thank you :slight_smile:

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