Writing data to SQL Server with Python Python Programming for beginners
Music by Bensound, www.bensound.com
import dbconfigs
import pyodbc
import pandas as pd
cn1= pyodbc.connect(r'DRIVER=SQL Server;'
f'Server={dbconfigs.SERVERNAME};'
r'Database=TestData;'
f'User ID={dbconfigs.USER};'
f'Password={dbconfigs.PASSWORD}'
)
csr = cn1.cursor()
data = pd.read_csv(r'clientdata.txt')
df = pd.DataFrame(data)
print(df)
for row in df.itertuples():
print(f"{row.name} - {row.surname} - {row.telnumber}")
qry = f"""INSERT INTO ClientData(ClientName, ClientSurname, ClientTel)
VALUES('{row.name}','{row.surname}',{row.telnumber})
"""
print(qry)
csr.execute(qry)
csr.commit()
csr.close()
On this page of the site you can watch the video online Writing data to SQL Server with Python - Python Programming for beginners with a duration of hours minute second in good quality, which was uploaded by the user Brendan Callaghan 31 March 2023, share the link with friends and acquaintances, this video has already been watched 2,672 times on youtube and it was liked by 12 viewers. Enjoy your viewing!