当前位置: 代码迷 >> ASP.NET >> 从数据库中(SQL)中读取image字段,该如何解决
  详细解决方案

从数据库中(SQL)中读取image字段,该如何解决

热度:6371   发布时间:2013-02-25 00:00:00.0
从数据库中(SQL)中读取image字段
我用的是VS2005,试了好多次,总是不行,就是那个stream类在2005里好象用不了,是不是要导入哪个命名空间?     请高手指点,最好是能给代码     谢谢了啊!!急

------解决方案--------------------------------------------------------
using System.IO
------解决方案--------------------------------------------------------
FileStream Fs = new FileStream(Path, FileMode.OpenOrCreate, FileAccess.Read, FileShare.None);
byte[] MyBinData = new byte[Fs.Length];
Fs.Write(数据库Image字段, 0, Bytes.Length);
Fs.Close();
------解决方案--------------------------------------------------------
FileStream 在System.IO里
------解决方案--------------------------------------------------------
Dim sql As String = "Select * from ServiceAttachment where ServiceAttachmentKey= ' " & Attkey & " ' "
Dim comm As New SqlCommand(sql, cn)
Dim drr As System.Data.SqlClient.SqlDataReader = comm.ExecuteReader
If drr.Read Then
Dim imagedata As Byte() = CType(drr.Item( "DocumentData "), Byte())
SaveBytesToFile(filename, imagedata) ' ' 'function
End if
Public function SaveBytesToFile(ByVal strName As String, ByVal data As Byte())
Try
Dim fInfo As FileInfo = New FileInfo(strName)
If fInfo.Exists Then
fInfo.Delete()
End If
Dim fs As New FileStream(strName, FileMode.CreateNew)
Dim w As New BinaryWriter(fs)
w.Write(data)
w.Flush()
fs.Close()
Catch ee As Exception
Throw New Exception(ee.Message)
End Try
End Sub
  相关解决方案