Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
This is my error when I wanted to insert image from SQL query analyzer.
Disallowed implicit conversion from data type varchar to data type varbinary, table 'Northwind.dbo.files', column 'filecontent'. Use the CONVERT function to run this query.

My queries are
SQL
Create table files(autoid int, filename varchar(50), filecontent image, isactive varchar(50))

insert into files(autoid,filename,filecontent,isactive) values(12,'google','C:\jtsimg.jpg','yes')

select * from files


Please help me to solve this error.
Thanks in advance dear friends.
Posted
Updated 6-Apr-12 7:36am
v3
Comments
André Kraak 6-Apr-12 13:23pm    
Edited question:
Added pre tags

The filecontent field should contain the binary file and not the path to the image file. This conversion fails during the insert.
You cant do this directly via management studio.
Instead try
insert into files(autoid,filename,filecontent,isactive) 
SELECT 12, 'google', BulkColumn 
FROM Openrowset( Bulk 'C:\jtsimg.jpg', Single_Blob) as pic, 'yes'
 
Share this answer
 
Comments
karthikh87 6-Apr-12 13:44pm    
thanks for reply and i got this error can u plz check with this error?
Server: Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'Bulk'.
Try this please

SQL
insert into files(autoid,filename,isactive,filecontent)
select 1 ,'test file name' ,'no',*
from openrowset (Bulk 'C:\bala.jpg',single_blob) as image
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900