-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcrud.py
More file actions
21 lines (19 loc) · 747 Bytes
/
crud.py
File metadata and controls
21 lines (19 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import pyodbc # pip install pyodbc
try:
conn = pyodbc.connect('Driver={SQL Server};'
'Server=localhost;'
'Database=Estudiante;'
'UID: Hola;'
'PWD: Hola;'
'Trusted_Connection=yes;')
print("Conexion exitosa")
except Exception as e:
print("Ocurrio un error al conectar a SQL Server: ", e)
# Create
def crear (id, nombre, apellido):
cursor = conn.cursor()
cursor.execute(' INSERT INTO ESTUDIANTE VALUES (?,?,?)', (id, nombre, apellido))
cursor.commit()
print("Estudiante creado con exito")
cursor.close()
return 'Estudiante creado con exito HTML'