Store image in database and retrieve it

后端 未结 4 1489
深忆病人
深忆病人 2021-01-28 07:36

My code for inserting image in database is as follows:

MemoryStream ms =new MemoryStream();
byte[] PhotoByte=null;
PhotoByte=ms.ToArray();
pictureBox1.Image.Save         


        
4条回答
  •  囚心锁ツ
    2021-01-28 08:19

    You should be using a parameterized query instead of concatenating a SQL string.

    Apart from fixing the obvious SQL Injection vulnerability, this will enable you to properly insert an image into the database.

    There are many questions and answers on how to insert into a SQL Server image/binary field - you should look at them.

提交回复
热议问题