首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

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

2012-02-07 
从数据库中(SQL)中读取image字段我用的是VS2005,试了好多次,总是不行,就是那个stream类在2005里好象用不了

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

热点排行