两种解决办法:
  1、将路径与文件名存入数据库
  2、在数据库表中建立BLOB等二进制大文本类型域。  真正的朋友

解决方案 »

  1.   

    答案:
    用来存储图片的字段PIC用Image类型:
    包括读写两部分.
    哎,舍不得呀,还是贴出来了,没有文件大小限制.'***********************************************
    Dim Conn As New ADODB.Connection
    Dim FileName As String
    Const BLOCKSIZE = 4096
    Dim ADORst As New ADODB.Recordset 'ADODB Recordset
    Dim ADOFld As ADODB.FieldPrivate Sub Command1_Click()Save_Click  Dim arsfile As ADODB.Recordset
      Dim aa As ADODB.Record
         Dim n As Long
         Dim arrBytes() As Byte
         
     
     Set arsfile = New Recordset
     arsfile.Open "select * from A_file where id=2", Conn, adOpenStatic, adLockOptimisticn = arsfile.Fields("word").ActualSize
    ReDim arrBytes(1 To n) As Byte
    arrBytes = arsfile.Fields("PIC").GetChunk(n)    Open App.Path & "\test2.jpg" For Binary As #1
         Put #1, , arrBytes
         Close #1End SubPrivate Sub Form_Load()
    Set Conn = New Connection
    Conn.CursorLocation = adUseClient
    Conn.Provider = "MSDataShape"
    Conn.Open "driver={sql server};server=10.0.0.1;uid=sa;pwd=;database=cmstest;"
    ADORst.Open "A_File", Conn, adOpenDynamic, adLockOptimistic
    'Set ADOFld.Recordset = ADORst '
    End Sub  Private Sub SaveToDB(ByRef Fld As ADODB.Field, DiskFile As String)
      Dim byteData() As Byte
      Dim NumBlocks As Long 
      Dim FileLength As Long
      Dim LeftOver As Long 
      Dim SourceFile As Long
      Dim i As Long 
      SourceFile = FreeFile 
      Open App.Path & "\test.jpg" For Binary Access Read As SourceFile  
      FileLength = LOF(SourceFile) 
      If FileLength = 0 Then 
      Close SourceFile
      MsgBox DiskFile
      Else
      NumBlocks = FileLength \ BLOCKSIZE 
      LeftOver = FileLength Mod BLOCKSIZE
      Fld.Value = Null
      ReDim byteData(BLOCKSIZE) 
      For i = 1 To NumBlocks
      Get SourceFile, , byteData() 
      Fld.AppendChunk byteData() 
      
      Next i
      ReDim byteData(LeftOver)
      Get SourceFile, , byteData() 
      Fld.AppendChunk byteData() 
      Close SourceFile 
      End If
      End Sub Private Sub Save_Click()
      ADORst.AddNew
      ADORst("id").Value = 2
      Set ADOFld = ADORst("PIC")
      Call SaveToDB(ADOFld, FileName)  ADORst.Update
     End Sub
      

  2.   

    请问楼上的,NumBlocks = FileLength \ BLOCKSIZE 
    这句的作用是什么呢。
      

  3.   

    请问楼上的,NumBlocks = FileLength \ BLOCKSIZE 
    这句的作用是什么呢。补充:
    为什么在for 中不直接用filelength???
      

  4.   

    在vb.net里好象不行啊。
    get命令用了fileget代替。
    如果想把一个内容赋值给数组,不行啊。