Click here to Skip to main content
15,902,189 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im using a qrcode to display image but i don't know how to save it in sql server.

What I have tried:

this is how i display image from qr to picturebox:

byte[] imageBytes = dr["SmStockImage"] as byte[];
if (imageBytes != null)
{
using (var stream = new MemoryStream(imageBytes))
pbxBagImg.Image = Image.FromStream(stream);
}
Posted
Updated 18-Jul-18 6:43am

1 solution

To get the bytes for the image, do the following. Note: if you're not using JPEG, change the format.

byte[] bytes;

using (var stream = new MemoryStream())
{
  image.Save(stream, ImageFormat.Jpeg);
  stream.Flush();

  bytes = stream.ToArray();
}



This assumes image is a variable you have previously initialized with the image you want to save.

After this, you just pass the value of bytes as a parameter into your SQL INSERT command.
 
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