Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query.

How to insert/update image column om SQL?

When you try to do this on sql server 2008 you got an error

update [tbl_items] set [ImagePlayer]='C:\Projects\Images\item.jpg' where [ID]=1

The error message was:

Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query.


Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query

All you need is to do BulkColumn

Code for update

update [tbl_items] set [ImagePlayer]=BulkColumn FROM OPENROWSET(Bulk 'C:\Projects\Images\item.jpg', SINGLE_BLOB) AS BLOB where [ID]=1


(1 row(s) affected)

Code for Insert

INSERT INTO [ScoutMe].[dbo].[tbl_Players]   ([ID],   [ImagePlayer])   SELECT 1,      BulkColumn FROM OPENROWSET(       Bulk 'C:\Projects\Images\item.jpg', SINGLE_BLOB) AS BLOB

Yours,
Roi Kolbinger :)


Comments

Popular posts from this blog

A sharepoint list view of the current month

The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters

Export SharePoint 2010 List to Excel with PowerShell