VB 利用ADO的Stream对象在数据库进行写入与读出

VB 利用ADO的Stream对象在数据库进行写入与读出,第1张

概述1、stream只是一个媒介,它在数据库字段与实际的图片间充当一个搬运工作用。       当读出时,图片字段写入stream中,,然后stream导出成一个实际图片        当写入时,实际图片装入stream中,,然后字段再从steam中读取       注意:这里写和读,是字段对stream的 *** 作。从数据库中取出数据,相当于字段先写到stream中。                  

1、stream只是一个媒介,它在数据库字段与实际的图片间充当一个搬运工作用。

当读出时,图片字段写入stream中,,然后stream导出成一个实际图片

当写入时,实际图片装入stream中,,然后字段再从steam中读取

注意:这里写和读,是字段对stream的 *** 作。从数据库中取出数据,相当于字段先写到stream中。

从外面写数据到数据库,相当于字段从stream中读取存盘。



2、利用rs.addnew和rs.update进行记录的新增和更新。



3、引用ADO 2.5或以上

Dim cn  As New ADODB.ConnectionDim rs  As New ADODB.RecordsetDim stm As New ADODB.StreamPrivate Sub Command1_Click() '读取    cn.Open    rs.Open "select * from 图书销售员 where 员工号='" & MSHFlexGrID1.TextMatrix(MSHFlexGrID1.RowSel,1) & "'",cn,adOpenKeyset,adLockOptimistic    If Not rs.EOF Then        If IsNull(rs.FIElds("照片")) Then            Image1.Picture = LoadPicture("")        Else            stm.Open            stm.Type = adTypeBinary            stm.Write rs.FIElds("照片")   '写进stream对象中            stm.Savetofile App.Path & ".gif",adSaveCreateOverWrite  '由stream导出成文件            Image1.Picture = LoadPicture(App.Path & ".gif")            stm.Close        End If    End If    rs.Close    cn.CloseEnd SubPrivate Sub Command2_Click() '写入    cn.Open    rs.Open "select * from 图书销售员 where 员工号='" & MSHFlexGrID1.TextMatrix(MSHFlexGrID1.RowSel,adLockOptimistic    If Not rs.EOF Then        If IsNull(rs.FIElds(3)) Then            Image1.Picture = LoadPicture("")            stm.Open            stm.Type = adTypeBinary            stm.LoadFromfile "D:\a.gif"  '实际文件装进stream            rs.FIElds(3).Value = stm.Read            rs.Update            stm.Close        End If    End If    rs.Close    cn.CloseEnd SubPrivate Sub Form_Load()    cn.Open "ProvIDer=sqlolEDB.1;Password=123;Persist Security Info=True;User ID=sa;Initial Catalog=book;Data Source=ZHENG"    Set MSHFlexGrID1.DataSource = cn.Execute("select * from 图书销售员")    cn.Close    Text1.Text = MSHFlexGrID1.RowSelEnd SubPrivate Sub MSHFlexGrID1_SelChange()    Text1.Text = MSHFlexGrID1.RowSelEnd Sub
总结

以上是内存溢出为你收集整理的VB 利用ADO的Stream对象在数据库进行写入与读出全部内容,希望文章能够帮你解决VB 利用ADO的Stream对象在数据库进行写入与读出所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1280120.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存