Skip to main content

Add data into sqlite database

 Here in this blog we are going to discuss about the `adding of the data into the database system.

So this is the procedure to do so



=========================================================================

from tkinter import *
import sqlite3
from tkinter import ttk
root=Tk()
root.geometry("400x500")
root.title("auto society")

conn = sqlite3.connect("society_sample.db")
c = conn.cursor()
# create table
c.execute(
    """CREATE TABLE IF NOT EXISTS sample_society(
code text,
society text,
socde text)"""
)
def add():
    # create a database or connect to one
    conn = sqlite3.connect('society_sample.db')
    # create cursor()
    c = conn.cursor()

    # insert into table
    c.execute(
        "INSERT INTO sample_society VALUES(:society,:code,:socde)",
        {
            'society': en1.get(),
            'code': en2.get(),
            'socde': en2.get()+"-"+en1.get()})

    # commit changes
    conn.commit()


    # close connection
    conn.close()
    en1.delete(0,END)
    en2.delete(0,END)

la1=Label(root,text="Society")
la1.grid(row=0,column=0)
en1=Entry(root)
en1.grid(row=0,column=1)

la2=Label(root,text="Code")
la2.grid(row=1,column=0)
en2=Entry(root)
en2.grid(row=1,column=1)


but25=Button(root,text="ADD",command=add)
but25.grid(row=2,column=0)

# commit changes
conn.commit()

# close connection
conn.close()


root.mainloop()

Comments

Popular posts from this blog

How to add the treeview numbers to get the grand total in tkinter entry box

 in this blog we are going to know about the adding of the integers in the treeview and get the total in the entry box of tkinter so here is the image first so the coding to do such things are here as follow but here is the condition that pls make assured that the state of entry box is disabled.......      for child in my_tree1 . get_children ():         e2l . config ( state = "normal" )         b1 += float ( my_tree1 . item ( child , "values" )[ 3 ])         var2 . set ( b1 )         e2l . config ( state = "disable" )      l2l = Label ( ento , text = "Purnea-2" , width = 8 )      l2l . grid ( row = 0 , column = 1 )     e2l = Entry ( ento , textvariable = var2 , state = "disable" , width = 8 )     e2l . grid ( row = 1 , column = 1 )