daily pastebin goal
2%
SHARE
TWEET

Untitled

a guest Feb 24th, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top