C:\Program Files\Microsoft SQL Server\80\Tools\Devtools\Samples\ADO\VB\Employee请参考实例

解决方案 »

  1.   

    方法就不说了,直接给你写例子吧!
    几点解释:
    一、使用了一个stm的Stream对象,该对象的作用是从操作系统的文件中读出二进制数据,并把二进制数据写到SqlServer 数据库中;
    二、1=2子句的作用是确保不向应用程序返回多余的数据!使用ADO Stream对象将一个位图文件输入到SQL Server表中:
    Private Sub ImportBLOB(cn As ADODB.Connection)
    Dim rs As New ADODB.RecordSet
    Dim stm As ADODB.Stream
    Set stm=New ADODB.Stream
    'Skip any table not found errors
    On Error Resume Next
    cn.Execute "drop table BinaryObject"
     
    On Error Goto 0
    'Create the BinaryObject table
    cn.Execute "Create table BinaryObject" & _
               "(blob_id int IDENTITY(1,1)," & _
               "blob_filename varchar(256)," & _
               "blob_object image)"
    rs.Open "Select * From BinaryObject Where 1=2",cn,adOpenKeySet,adLockOptimistic
    'Read the binary files from disk
    stm.Type=adTypeBinary
    stm.Open
    stm.LoadFromFile App.Path & "\BLOBsample.jpg"rs.AddNew
    rs!blob_filename=App.Path & "\BLOBsample.jpg"
    rs!blob_object=stm.Read'Insert the binary object in the table 
    rs.Updaters.Close
    stm.CloseSet rs=Nothing
    Set stm=NothingEnd Sub
      

  2.   

    显示就相对简单了!
    使用ADO RecordSet来检索数据,并绑定到Image控件imgBinaryData进行显示:
    Private Sub DisplayBLOB(cn As ADODB.Connection)Dim rs As New ADODB.RecordSet'Select the only image in the table
    rs.Open "Select * From BinaryObject Where blob_id=1",cn'Set the DataSource to the RecordSet
    Set imgBinaryData.DataSource=rs
    'Set the DataField to the BLOB Field 
    imgBinaryData.DataField=rs!blob_object.Name'Release the RecordSet
    rs.Close
    Set rs=NothingEnd Sub
      

  3.   

    to w18ily(看.net没几天) :
       thanks very much!!