How to save picture in the database

前端 未结 1 480
野的像风
野的像风 2021-01-22 00:53

I am using following code to save my data to database Where does the statement to save a picture in the database fit?

        Dim drNewRowMCQsAns As DataRow
             


        
相关标签:
1条回答
  • 2021-01-22 01:27

    Well, the image data is simply a byte array

    Dim imageData as Byte()
    

    Load your image into the byte array from where ever you are getting it from and set it just like the other properties

    drNewRowMCQsAns.Item("ImageData") = imageData
    

    Loading image into array:

    From file:

            imageData = IO.File.ReadAllBytes("c:\filename.jpg")
    

    From bitmap:

            Dim bitmap As New System.Drawing.Bitmap("c:\filename.jpg")
        Dim tempMemStream As New IO.MemoryStream
        bitmap.Save(tempMemStream, System.Drawing.Imaging.ImageFormat.Jpeg)
        imageData = tempMemStream.ToArray()
    
    0 讨论(0)
提交回复
热议问题