Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Insert Value to SQL
- import pyodbc
- cnxn = pyodbc.connect(Driver='{SQL Server}',Server='DESKTOP\SQLEXPRESS',Database='TEST',Trusted_Connection='yes')
- cursor = cnxn.cursor()
- #cursor.execute('SELECT * from [TEST].[dbo].[Table_1]')
- cursor.execute('INSERT INTO [TEST].[dbo].[Table_2] VALUES (6, 6)')
- cursor.commit()
- cnxn.close()
- # Read Sql Data
- import pyodbc
- cnxn = pyodbc.connect(Driver='{SQL Server}',Server='DESKTOP\SQLEXPRESS',Database='TEST',Trusted_Connection='yes')
- cursor = cnxn.cursor()
- #cursor.execute('SELECT * from [TEST].[dbo].[Table_1]')
- while 1:
- row = cursor.fetchone()
- if not row:
- break
- print(row)
- cnxn.close()
Add Comment
Please, Sign In to add comment