怎样用vb把本地的bmp,gif文件存到数据库中去

Axiong 2000-07-11 05:23:00
Dim a As Variant
Dim MyChar As Byte
a = ""
Open "w:\hare.bmp" For Binary Access Read As #1 ' Open file.
Do While Not EOF(1) ' Loop until end of file.
Get #1, , MyChar
'Debug.Print MyChar ' Print to the Immediate window.
a = a + ChrB(MyChar)
Loop
Close #1 ' Close file.


????????
怎么用ado存a到pubs.pub_info


mssql70,database:pubs,dns:pubs,pws:='',user:sa,table:pub_info
...全文
111 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
TopHead 2000-07-11
  • 打赏
  • 举报
回复
'将图片存入数据库
'首先将文件读入一字节数组
Dim bit() As Byte
Open "C:\WINDOWS\安装程序.bmp" For Binary As #1
ReDim bit(LOF(1)) As Byte
Get 1, 1, bit
Close 1

'然后将字节数组的内容写入数据库即可
Dim cnn As New ADODB.Connection, rst As New ADODB.Recordset
cnn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Northwind;Data Source=rdm"
rst.Open "T1", cnn, adOpenKeyset, adLockOptimistic
rst.AddNew
rst("F1").AppendChunk bit
rst.Update
'
' '将数据库中的图片读出
' '首先将数据库中的内容读到一字节数组
' Dim bit1() As Byte
' bit1 = rst("F1").GetChunk(rst("F1").ActualSize)
' '然后将字节数组的内容拼装成文件即可
' Open "c:\1.bmp" For Binary As #1
' Put 1, 1, bit1
' Close 1
' Me.Picture = LoadPicture("c:\1.bmp")


liyang 2000-07-11
  • 打赏
  • 举报
回复
dim acnTemp as new Adodb.connection
dim astTemp as new adodb.recordset

acntemp.open "privider=SQLOLEDB.1;Data Source=Pubs;User ID=sa;Password=pwd;Auto Translate=false"
if acntemp.state then
astTemp.open "select Field1 from ub_info",acnTemp,adOpenForwardOnly,_
adLockOptimistic
astTemp.Addnew
astTemp("Field")=a
astTemp.Update
astTemp.close
endif
acntemp.close

在Ado中,LOB字段可以直接赋值,不需要GetChunk.

1,216

社区成员

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

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