Question
I need to take an Image datatype from one SQL database and insert it into a second database that is using nvarchar(max) for images.
Is nvarchar(max) what they should be using? When I do an insert, the image appears as System.byte[] in the table. Should there be a cast or convert done to the image datatype to get it to work?
The query as below:
Select [mypicture] from [dbo].[oldtable] into a datareader (drPic.Item("mypicture")) (image datatype)
Update [dbo].[newtable] Set [mypicture] = drPic.Item("mypicture") (nvarchar(max) datatype)
Answer
varchar is for characters, you should use varbinary instead. If you really want to use a varchar field, you need to encode your image.
Reference
Microsoft SQL Docs > SQL > Reference > Transact-SQL (T-SQL) Reference > String & binary > binary and varbinary (Transact-SQL)