-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.py
31 lines (24 loc) · 1.04 KB
/
db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import pyodbc # For python3 MSSQL
cnxn = pyodbc.connect("Driver={SQL Server};" # For Connection
"Server=RAPTAR\SQLEXPRESS;"
"Database=Emprecords;"
"Trusted_Connection=yes"
"Uid=mayan;"
"Pwd=pass@123;")
cursor = cnxn.cursor() # Cursor Establishment
cursor.execute('select * from Emptable') # Execute Query
# cursor.fetchall()
# print(cursor.fetchone()) # fetch the first row only
# cnxn.close()
for row in cursor.fetchall():
print(row.Empid, row.Empname)
# cnxn = pyodbc.connect("Driver={ODBC Driver 17 for SQL Server};" # For Connection
# "Server=49.50.100.159,5263;"
# "Database=practicemk;"
# # "Trusted_Connection=yes"
# "Uid=mayankmr2;"
# "Pwd=Mayan@1198;")
# cursor = cnxn.cursor() # Cursor Establishment
# cursor.execute('select * from student') # Execute Query
# for row in cursor:
# print('row = %r' % (row,))