如何在数据库中保存图片 [英] How to save picture in the database

查看:107
本文介绍了如何在数据库中保存图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用以下代码将数据保存到数据库中,将图片保存到数据库中的语句在哪里合适?

Hi,
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
        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)




我的数据库中有图像字段,但是如何保存图像?
谢谢




I have image field in the database but how to save an image?
Thanks

推荐答案

您还没有发布足够的信息来真正为您提供帮助.您发布的代码似乎与将图片加载到数据库中实际上没有任何关系……看起来您只是在保存几个字符串或数字字段.尝试阅读一些 CP文章 [ ^ ]寻求帮助,或发布更多信息.

(此处 [
You haven''t posted enough information to really help you. The code you posted doesn''t really seem to have anything to do with loading a picture into a database...it looks like you are just saving a couple of string or number fields. Try reading some of the CP Articles[^] for help, or post more information.

(Here[^] is another CP Articles search with different keywords that might help)


将图像保存到MemoryStream对象,并将MemoryStream.GetBuffer()作为参数传递给存储过程.
Save the image to a MemoryStream object, and pass MemoryStream.GetBuffer() as a parameter to your stored procedure.


This code sample in C# (will be not difficult to convert in VB.NET) works well to read images from database and bind dataset with a gridview control.
To get image from gridview and save it in file use MemoryStream Object like here:
'Initialize image variable
 Dim newImage As Image
 'Read image data into a memory stream
 Using ms As New MemoryStream(imageData, 0, imageData.Length)
  ms.Write(imageData, 0, imageData.Length)
  'Set image variable value using memory stream.

     newImage = Image.FromStream(ms, True)
  'Store selected image to a local file in current directory:
     newImage.Save(".\picture.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
 End Using


这篇关于如何在数据库中保存图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆