1

I have a column named IMGDATA of type Image in my MyImages in SQL Server server I have a string variable named MyImageStringBase64Encoded that contains a base64 encoded image. I m trying to save this image to the database

Set Command1 = Server.CreateObject ("ADODB.Command")
Command1.ActiveConnection = MyConnection_STRING
Command1.CommandText = "INSERT INTO MyImages (IMGNAME,IMGDATA)  VALUES (?,?)"
Command1.Parameters(0) = "My Image Name"
Command1.Parameters(1) = MyImageStringBase64Encoded
Command1.CommandType = 1
Command1.Execute()

The code above will save corrupted image data in the db. Maybe I have to save bytes?

possibly related but not sure how to apply them

https://stackoverflow.com/a/24925145/934967

MS Access: Sending image as varbinary to stored procedure

I 'm new to vbscript

6
  • 1
    Does this answer your question? Converting from base64 string to varbinary(max) in SQL Server Commented Sep 11, 2020 at 14:58
  • You need to convert the base64 encoded string into it’s binary representation before saving it to SQL Server. Commented Sep 11, 2020 at 15:00
  • Just noticed you mention mysql in the question but the question is tagged sql-server, which is it? Commented Sep 11, 2020 at 15:01
  • The image data type has been deprecated since SQL Server 2005, you should use the varbinary(max) column type instead. You also shouldn't need to base64 encode it, just supply a byte array to the CreateParameter method with the Type set to adBinary. Commented Sep 11, 2020 at 15:02
  • @AlwaysLearning still depends on if they are using sql-server or not but would suggest adVarBinary over adBinary. Commented Sep 11, 2020 at 15:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.