Click here to Skip to main content
15,113,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
M_PIC.Image = TRN_LIB.ConvertBinaryToImage((byte[])tbl1.Rows[0]["M_IMG"]);

!! M_PIC it's the pictureBox


 public Image ConvertBinaryToImage(byte[] data)
        {
            using (MemoryStream ms = new MemoryStream(data))
            {
                return Image.FromStream(ms);
            }

        }

to save 
 public byte[] ConverImageToBinary(Image img)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                img.Save(ms, ImageFormat.Jpeg);
                return ms.ToArray();
            }
        }

the column on mssql 2019 express it's image type

if try more than one sluoson but, i have the error


What I have tried:

if i user the file path , can i view the pic
Posted
Updated 24-Feb-20 6:10am

1 solution

It's not that code - it's your INSERT code: Why do I get a "Parameter is not valid." exception when I read an image from my database?[^]

And that probably means that your whole app is vulnerable to SQL Injection - you need to fix that throughout as a matter for highest priority. Never concatenate strings to build a SQL command!
   

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