怎样将数据库中的图片字段取出存为一个临时的图片文件?

kevenzhang 2001-11-13 02:57:05
...全文
124 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
kevenzhang 2001-11-13
  • 打赏
  • 举报
回复
我不知道别人怎么写的呀 ,我不能都把它存为BMP吧
solitude 2001-11-13
  • 打赏
  • 举报
回复
to : kevenzhang(向往高手) 
你怎么写进出的就怎么读出来
kevenzhang 2001-11-13
  • 打赏
  • 举报
回复
如果我不知道数据库中是GIF,还是BMP,或JPG,TIF,甚至是EXE,我怎么还原它当初的
文件格式呢?
yangzhaoyu 2001-11-13
  • 打赏
  • 举报
回复
http://support.microsoft.com/support/kb/articles/Q153/2/38.asp
foolishtiger 2001-11-13
  • 打赏
  • 举报
回复
我贴的是我程序里的一段代码,把指定ID的文件,由用户通过对话框指出要保存的位置,然后把Content字段的内容(该字段的内容是图片)保存成用户指定的文件名

这段代码我几乎每天都要运行.
kevenzhang 2001-11-13
  • 打赏
  • 举报
回复
我的RECORDSET对象没有ACTUALSIZE这个属性呀,告诉我怎办
kevenzhang 2001-11-13
  • 打赏
  • 举报
回复
foolishtiger(吴文智):
我用的是ADO,字段是“图象”,你说怎写吧,我有点看不明?
fishzone 2001-11-13
  • 打赏
  • 举报
回复
http://www.csdn.net/expert/topic/242/242007.shtm
给你贴出来吧!
'可以用临时文件的方法来储存和读出文件

'储存
Private Sub SavePic()
Dim Conn As New ADODB.Connection
Dim Rs0 As New ADODB.Recordset
Dim Rs As New ADODB.Recordset
Dim Maxnumber As Long
Dim Sql As String
Dim Connstr As String

Connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=joybig;Data Source=" & App.Path & "\pic.mdb;Persist Security Info=False"
Conn.Open Connstr
Rs.CursorLocation = adUseClient
Rs.CursorType = adOpenKeyset
Rs.LockType = adLockOptimistic
DoEvents

Dim picarray() As Byte
Dim piclenth As Long
Rs.Open "save", Conn, , , adCmdTable
Rs.AddNew
Rs("title") = Trim(Text3.Text)
If Trim(Text1.Text) = "在此处输入备注信息" Then
Rs("note") = ""
Else
Rs("note") = Trim(Text1.Text)
End If
piclenth = FileLen(App.Path & "\mydoc.doc")
ReDim picarray(piclenth)
Open App.Path & "\mydoc.doc" For Binary Access Read As #1
Get #1, , picarray()
Close #1
Rs("pic").AppendChunk picarray
Rs.Update
Rs.Close
Set Rs = Nothing
Set Conn = Nothing
End Sub

'读出
Private Sub ReadPic()
Dim Conn As New ADODB.Connection
Dim Rs0 As New ADODB.Recordset
Dim Rs As New ADODB.Recordset
Dim Maxnumber As Long
Dim Sql As String
Dim Connstr As String
Dim picarray() As Byte
Dim piclenth As Long

Connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=joybig;Data Source=" & App.Path & "\pic.mdb;Persist Security Info=False"
Conn.Open Connstr
Rs.CursorLocation = adUseClient
Rs.CursorType = adOpenKeyset
Rs.LockType = adLockOptimistic
DoEvents

Rs.Open "select * from [save]", Conn, adOpenKeyset, adLockOptimistic
Text2.Text = Rs("title")
Text4.Text = Rs("note")
piclenth = Rs("pic").ActualSize

ReDim picarray(piclenth)
picarray = Rs("pic").GetChunk(piclenth)

Open App.Path & "\doc1.doc" For Binary Access Write As #1
Put #1, , picarray()
Close #1
Picture1.Picture = LoadPicture(App.Path & "\doc1.doc")
Rs.Close
Set Rs = Nothing
Set Conn = Nothing
End Sub
foolishtiger 2001-11-13
  • 打赏
  • 举报
回复
从数据库取文件出来
Public Sub SaveFile(ByVal FileID As Long)
Dim lngBlockCount As Long
Dim lngLastBlock As Long
Dim lngI As Long
Dim btyBlock() As Byte
Dim lngResult As Long

If rsBinary.EOF And rsBinary.BOF Then Exit Sub
rsBinary.MoveFirst
rsBinary.Find " id=" & FileID
If Not rsBinary.EOF Then
With frmBinary.CommonDialog1
.FileName ="TempSave"
'.InitDir = App.Path

'If user cancel save the goto handle
On Error GoTo ErrorHandle
.ShowSave
If .FileName <> "" Then
lngBlockCount = rsBinary.Fields("content").ActualSize \ BlockSize
lngLastBlock = rsBinary.Fields("content").ActualSize Mod BlockSize

If Dir(.FileName) <> "" Then
If MsgBox("File " & .FileName & " is exist,overwrite?", vbYesNo + vbQuestion) = vbYes Then
Kill .FileName
Else
Exit Sub
End If
Else
End If

Open .FileName For Binary As #1

ReDim btyBinary(BlockSize)

For lngI = 1 To lngBlockCount
btyBlock() = rsBinary.Fields("content").GetChunk(BlockSize)
Put #1, , btyBlock
Next

If lngLastBlock <> 0 Then
ReDim btyBlock(lngLastBlock)
btyBlock() = rsBinary.Fields("content").GetChunk(lngLastBlock)
Put #1, , btyBlock
End If

Close #1
MsgBox .FileName & " is saved", vbInformation
Else
End If
End With
End If

Exit Sub
ErrorHandle:

End Sub


1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧