我使用以下代码将数据保存到数据库 在数据库中保存图片的语句在哪里适合?
Dim drNewRowMCQsAns As DataRow
drNewRowMCQsAns = DsResultSaveNow.tblResult.NewRow
drNewRowMCQsAns.Item("PaperID") = vrPaperIDInitialized
drNewRowMCQsAns.Item("StudentID") = vrStudentID
drNewRowMCQsAns.Item("StudentName") = vrStudentName
DsResultSaveNow.tblResult.Rows.Add(drNewRowMCQsAns)
taResultSaveNow.Update(DsResultSaveNow.tblResult)
我在数据库中有图像字段但是如何保存图像? 感谢
答案 0 :(得分:1)
嗯,图像数据只是一个字节数组
Dim imageData as Byte()
将图像加载到从中获取图像的字节数组中,并将其设置为与其他属性一样
drNewRowMCQsAns.Item("ImageData") = imageData
将图片加载到数组中:
来自档案:
imageData = IO.File.ReadAllBytes("c:\filename.jpg")
来自位图:
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()