In [ ]:
def createtable():
import sqlite3
mdb = sqlite3.connect('CS.db')
myc = mdb.cursor()
myc.execute('create table student5(name char(40),rollno int)')
mdb.close()
def insert():
import sqlite3
mdb = sqlite3.connect('CS.db')
myc = mdb.cursor()
m=input("enter name")
n=input("rollno")
myc.execute("INSERT INTO student5 VALUES ('"+m+"','"+n+"')")
mdb.commit()
mdb.close()
def showdata():
import sqlite3
mdb = sqlite3.connect('CS.db')
myc = mdb.cursor()
myc.execute('select * from student5')
record=myc.fetchall()
for x in record:
print(x[0],x[1])
mdb.close()
while(True):
print("1.to Create Tale ")
print("2 to Insert Record ")
print("3 to Show Record")
print("4 to Exit")
ch=int(input("Enter Choice"))
if(ch==1):
createtable()
elif(ch==2):
insert()
elif(ch==3):
showdata()
elif(ch==4):
break
No comments:
Post a Comment