Guest User

Untitled

a guest
Feb 24th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. # Insert Value to SQL
  2. import pyodbc
  3. cnxn = pyodbc.connect(Driver='{SQL Server}',Server='DESKTOP\SQLEXPRESS',Database='TEST',Trusted_Connection='yes')
  4. cursor = cnxn.cursor()
  5. #cursor.execute('SELECT * from [TEST].[dbo].[Table_1]')
  6. cursor.execute('INSERT INTO [TEST].[dbo].[Table_2] VALUES (6, 6)')
  7. cursor.commit()
  8. cnxn.close()
  9.  
  10.  
  11. # Read Sql Data
  12. import pyodbc
  13. cnxn = pyodbc.connect(Driver='{SQL Server}',Server='DESKTOP\SQLEXPRESS',Database='TEST',Trusted_Connection='yes')
  14. cursor = cnxn.cursor()
  15. #cursor.execute('SELECT * from [TEST].[dbo].[Table_1]')
  16. while 1:
  17. row = cursor.fetchone()
  18. if not row:
  19. break
  20. print(row)
  21. cnxn.close()
Add Comment
Please, Sign In to add comment