Python ที่ใช้จะเป็น 3.6
ติดตั้ง pyodbc
โค้ด: เลือกทั้งหมด
pip install pyodbc
โค้ด: เลือกทั้งหมด
import pyodbc
โค้ด: เลือกทั้งหมด
SQLSERVER = 'COM011\SQLEXPRESS'
SQLDB = 'test_hip01'
str_conn = 'Driver={SQL Server};Server=%s;Database=%s;Trusted_Connection=yes;'%(SQLSERVER, SQLDB)
conn = pyodbc.connect(str_conn)
โค้ด: เลือกทั้งหมด
cursor = conn.cursor()
cursor.execute('SELECT st.*, emp.studentcode FROM [Transcantime] AS st LEFT JOIN [Student] AS emp ON st.enrollnumber = emp.enrollnumber;')
โค้ด: เลือกทั้งหมด
rows = cursor.fetchall()
for row in rows:
print(row)
โค้ด: เลือกทั้งหมด
import pyodbc
SQLSERVER = 'COM011\SQLEXPRESS'
SQLDB = 'test_hip01'
str_conn = 'Driver={SQL Server};Server=%s;Database=%s;Trusted_Connection=yes;'%(SQLSERVER, SQLDB)
conn = pyodbc.connect(str_conn)
cursor = conn.cursor()
cursor.execute('SELECT st.*, emp.studentcode FROM [Transcantime] AS st LEFT JOIN [Student] AS emp ON st.enrollnumber = emp.enrollnumber;')
rows = cursor.fetchall()
for row in rows:
print(row)
https://www.mindphp.com/vdo-tutorial-python.html
สอน Python พื้นฐานจาก Mindphp.com
https://www.mindphp.com/%E0%B8%9A%E0%B8 ... ython.html
เทคนิค Python
https://www.mindphp.com/developer/tips-python.html
บทเรียน Python GUI
https://www.mindphp.com/%E0%B8%9A%E0%B8 ... n-gui.html
บทเรียน Python Framework Flask
https://www.mindphp.com/%E0%B8%9A%E0%B8 ... flask.html
บทเรียน Python Tensorflow (เขียน AI)
https://www.mindphp.com/%E0%B8%9A%E0%B8 ... rflow.html
อ้างอิง
https://docs.microsoft.com/th-th/sql/connect/python/pyodbc/step-3-proof-of-concept-connecting-to-sql-using-pyodbc?view=sql-server-2017
https://stackoverflow.com/questions/33725862/connecting-to-microsoft-sql-server-using-python
https://www.tutorialgateway.org/connect-python-and-sql-server/