vb.net 中如何将图片保存到SQL数据库
如题,把图片保存到SQL数据库当中,有人推荐使用“保存路径”的方法。但是具体怎么做???如果想要直接保存到数据库当中,又该怎么做???可以的话给出具体的步骤和代码,以及注...
如题,把图片保存到SQL数据库当中,有人推荐使用“保存路径”的方法。但是具体怎么做???如果想要直接保存到数据库当中,又该怎么做??? 可以的话给出具体的步骤和代码,以及注释新人提问,答案越详细越好。
展开
2013-09-02
展开全部
#Region "二进制文件的存储函数" Public Function BinaryToFile(ByRef TableRowColItem As Object, ByVal FileName As String) As Boolean Dim data As Byte() = TableRowColItem
Dim myfilestream As New System.IO.FileStream(FileName, IO.FileMode.Create)
myfilestream.Write(data, 0, data.Length)
myfilestream.Close()
Return True
End Function Public Function BinaryToImage(ByRef TableRowColItem As Object, ByRef image As Image) As Boolean Dim data As Byte() = TableRowColItem Dim imgStream As New System.IO.MemoryStream '(data)
imgStream.Write(data, 0, data.Length)
image = System.Drawing.Image.FromStream(imgStream)
imgStream.Close()
imgStream.Dispose() Return True
End Function
Public Function BinaryFromFile(ByVal FileName As String, ByRef TableRowColItem As Object) As Boolean Using myfilestream As New FileStream(FileName, FileMode.Open, FileAccess.Read)
Dim data() As Byte
ReDim data(myfilestream.Length - 1)
myfilestream.Read(data, 0, myfilestream.Length)
myfilestream.Close()
TableRowColItem = data End Using
Return True
End Function Public Function BinaryFromImage(ByRef Image As Image, ByRef TableRowColItem As Object) As Boolean
Dim imgStream As New MemoryStream
Dim b As New Bitmap(Image) b.Save(imgStream, System.Drawing.Imaging.ImageFormat.Jpeg) Dim data As Byte() = imgStream.GetBuffer
TableRowColItem = data
data = TableRowColItem
imgStream.Close()
imgStream.Dispose() Return True
End Function Public Function BinaryFromImage(ByVal Image As Image, ByRef TableRowColItem As Object, ByVal imgFormat As System.Drawing.Imaging.ImageFormat) As Boolean
Dim imgStream As New MemoryStream
'Image.Save(imgStream, imgFormat)
'Dim b As New Bitmap(Image)
'b.Save("c:\a.bmp", imgFormat)
'b.Save("c:\a.bmp", imgFormat) Dim data As Byte() = imgStream.GetBuffer TableRowColItem = data
data = TableRowColItem
imgStream.Close()
Return True
End Function
#End Region
Dim myfilestream As New System.IO.FileStream(FileName, IO.FileMode.Create)
myfilestream.Write(data, 0, data.Length)
myfilestream.Close()
Return True
End Function Public Function BinaryToImage(ByRef TableRowColItem As Object, ByRef image As Image) As Boolean Dim data As Byte() = TableRowColItem Dim imgStream As New System.IO.MemoryStream '(data)
imgStream.Write(data, 0, data.Length)
image = System.Drawing.Image.FromStream(imgStream)
imgStream.Close()
imgStream.Dispose() Return True
End Function
Public Function BinaryFromFile(ByVal FileName As String, ByRef TableRowColItem As Object) As Boolean Using myfilestream As New FileStream(FileName, FileMode.Open, FileAccess.Read)
Dim data() As Byte
ReDim data(myfilestream.Length - 1)
myfilestream.Read(data, 0, myfilestream.Length)
myfilestream.Close()
TableRowColItem = data End Using
Return True
End Function Public Function BinaryFromImage(ByRef Image As Image, ByRef TableRowColItem As Object) As Boolean
Dim imgStream As New MemoryStream
Dim b As New Bitmap(Image) b.Save(imgStream, System.Drawing.Imaging.ImageFormat.Jpeg) Dim data As Byte() = imgStream.GetBuffer
TableRowColItem = data
data = TableRowColItem
imgStream.Close()
imgStream.Dispose() Return True
End Function Public Function BinaryFromImage(ByVal Image As Image, ByRef TableRowColItem As Object, ByVal imgFormat As System.Drawing.Imaging.ImageFormat) As Boolean
Dim imgStream As New MemoryStream
'Image.Save(imgStream, imgFormat)
'Dim b As New Bitmap(Image)
'b.Save("c:\a.bmp", imgFormat)
'b.Save("c:\a.bmp", imgFormat) Dim data As Byte() = imgStream.GetBuffer TableRowColItem = data
data = TableRowColItem
imgStream.Close()
Return True
End Function
#End Region
2013-09-02
展开全部
分两步1.把文件上传到你的项目里2.把文件名记录到数据库,使用时调用数据库里的图片名再加图片的路径找到图片就行了
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-09-02
展开全部
都是只保存路径的,把图片放到一个专用的文件夹下,读取的时候,从路径得图片
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |