Skip to Content

Solved: How do I move the image field into nvarchar(max) field in SQL/VB.Net syntax?

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)

How to Convert Image to Base64 in VB.Net

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. We need money to operate the site, and almost all of it comes from online advertising. Please support us by disabling these ads blocker.

Please disable ad blocker