vb 如何从数据库中读取二进制图片到临时文件中,然后又把它转回到数据库中

dmmd 2006-02-22 11:53:06
vb 如何从数据库中读取二进制图片到临时文件中,然后又把它转回到数据库中,在线等待
...全文
138 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
hongfof 2006-02-22
Dim con As New ADODB.Connection
Dim rec As ADODB.Recordset

Private Sub c1_Click()
'p.Filter = "图片文件(*.jpg,*.bmp)|*.jpg;*.bmp"
p.ShowOpen
t3.Text = p.FileName
'i.Picture = LoadPicture(p.FileName)
End Sub

Private Sub c2_Click()
Dim pic() As Byte
Dim lngFile As Long
Set rec = New Recordset
rec.Open "select * from stu where 1<>1", con, adOpenDynamic, adLockOptimistic, -1
lngFile = FreeFile
Open t3.Text For Binary As #lngFile
ReDim pic(LOF(lngFile))
Get #lngFile, , pic
Close #lngFile
rec.AddNew
rec.Fields(0).Value = t1.Text
rec.Fields(1).Value = t2.Text
rec.Fields(2).Value = pic
rec.Update
rec.Close
i.Picture = LoadPicture("")
End Sub

Private Sub c3_Click()
Dim pic() As Byte
Set rec = New Recordset
rec.Open "select * from stu where stu_id='" & t1.Text & "'", con
t2.Text = rec.Fields(1).Value
ReDim pic(rec.Fields(2).ActualSize) '返回2进制图片的字节长度
pic = rec.Fields(2).Value
Open App.Path & "\" & t1.Text For Binary As #1
Put #1, , pic
Close #1
'Set i.Picture = LoadPicture(App.Path & "\" & t1.Text)
'MsgBox App.Path
'Kill (App.Path & "\" & t1.Text)
End Sub

Private Sub Form_Load()
Set con = New Connection
con.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=kkk;Data Source=."
End Sub

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
这段代码是把一张图片存到数据库再读出来 而且还保存了个二进制文件在你工程那
回复
christion3 2006-02-22
以2进制方式建个文件,把数据酷中的内容读进去
回复
相关推荐
发帖

1188

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
帖子事件
创建了帖子
2006-02-22 11:53
社区公告
暂无公告