读书人

从数据库中(SQL)中读取image字段,该

发布时间: 2012-02-07 17:45:36 作者: rapoo

从数据库中(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

读书人网 >asp.net

热点推荐