Interfacing SQL with Python : Update Record
import mysql.connector as cn
con=cn.connect(host='localhost',user='root',password='root',database='stud_db')
if con.is_connected():
print("connected to the database....")
cr=con.cursor()
print("==============Program to Update record==============")
rn=int(input("Enter roll no. to update:"))
marks=int(input("Enter New Marks:"))
cr.execute("update student set marks=%s where rollno=%s"%(marks,rn))
con.commit()
cr.execute("select * from student")
data=cr.fetchall()
for rec in data:
print(rec)
Comments
Post a Comment