In this article, we save the data we entered with the
print command on the console screen with the Insert method into the MS Sql
Database.
Figure 1
Figure 2
import pyodbc
con1=pyodbc.connect(
'Driver={SQL Server};'
'Server=sirius\SQLEXPRESS02;'
'Database=master;'
'Trusted_Connection=yes;'
)
print("Enter a Staff Id")
Id=int(input())
print("Enter First Name")
Firstname=input()
print("Enter Last Name")
LastName=input()
print("Enter Contact")
Contact=input()
print("Enter Mail")
Mail=input()
print("Enter Gender")
Gender=input()
print("Enter Department")
Department=input()
print("Enter Address")
Address=input()
print("Enter PostalCode")
PostalCode=input()
print("Enter City")
City=input()
print("Enter State")
State=input()
print("Enter Country")
Country=input()
cursor = con1.cursor()
SQLCommand = ("INSERT INTO dbo.staff(Id,Firstname,LastName,Contact,Mail,Gender,Department,Address,PostalCode,City,State,Country) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)")
Values = [Id,Firstname,LastName,Contact,Mail,Gender,Department,Address,PostalCode,City,State,Country]
#Processing query.
cursor.execute(SQLCommand,Values)
#Committing any pending transaction to the database.
con1.commit()
print("Data Successfully Inserted. \n Verinin basarili bir sekilde girisi yapildi.")
con1.close()
Hope to see you in the next article. Happy coding.
No comments:
Post a Comment