Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

upload file to SQL server pyodbc python

# Get connection
connection = pyodbc.connect(...)
filename = 'MyFile.pdf'
insert = 'insert into FileTable (name, document) values (?,?)'

# open file as binary and read into a variable
with open(filename, 'rb') as f:
    bindata = f.read()

# build query
binparams = ('MyFile.pdf', pyodbc.Binary(bindata))

# insert binary
connection.cursor().execute(insert, binparams)
connection.commit()
connection.close()
Source by www.hackersfriend.com #
 
PREVIOUS NEXT
Tagged: #upload #file #SQL #server #pyodbc #python
ADD COMMENT
Topic
Name
3+3 =