如何将jpg的图片加入到sql server 的 image类型的字段中阿,使用ado,谢谢

解决方案 »

  1.   

    var
    MStream:TMemoryStream;
    begin
      if not PicDlg.Execute then exit;
      Screen.Cursor:=crHourGlass;
      MStream:=TMemoryStream.Create;
      try
        MStream.LoadFromFile(PicDlg.FileName);
        QryImg.Edit;
        try
          MStream.Position:=0;
          QryImgmaterialimg.LoadFromStream(MStream);
          QryImg.Post;
        except
          application.MessageBox('更改图片出错误!','程序提示',mb_iconstop);
        end;
      finally
        MStream.Free;
      end;
    end;
      

  2.   

    strID为图片的编号,strFileName为图片的路径名称,strTable为表格名
    表结构为三个字段ID,Nvarchar.   Imame.     Type,NvarcharSub SavePicture(strID As String, strFileName As String, strTable)
        On Error Resume Next
        Dim i As Integer
        Dim lngFileLen As Long
        Dim intFile As Integer
        Dim Chunks As Integer
        Dim Fragment As Integer
        Dim Chunk() As Byte
        Dim recPicture As ADODB.Recordset
        Dim ChunkSize As Integer
        ChunkSize = 16384
        Set recPicture = rsOpen("Select Id,Picture,Type From " & strTable & " Where Id='" & Trim(strID) & "' Order By Id")
        If recPicture.RecordCount = 0 Then
            recPicture.AddNew
            recPicture.Fields("Id") = Trim(strID)
        End If
        If strFileName <> "" And Dir(strFileName) <> "" Then
            i = InStrRev(strFileName, ".")
            If i <> 0 Then
                recPicture.Fields("Type") = Mid(strFileName, i + 1)
            Else
                recPicture.Fields("Type") = ""
            End If
            intFile = FreeFile
            Open strFileName For Binary Access Read As intFile
            lngFileLen = LOF(intFile)    ' &Icirc;&Auml;&frac14;&thorn;&Ouml;&ETH;&Ecirc;&yacute;&frac34;&Yacute;&sup3;¤&para;&Egrave;
            If lngFileLen = 0 Then
                Close intFile
                Exit Sub
            End If
            Chunks = lngFileLen \ ChunkSize
            Fragment = lngFileLen Mod ChunkSize
            ReDim Chunk(Fragment)
            Get intFile, , Chunk()
            recPicture.Fields("Picture").AppendChunk Chunk()
            ReDim Chunk(ChunkSize)
            For i = 1 To Chunks
                Get intFile, , Chunk()
                recPicture.Fields("Picture").AppendChunk Chunk()
            Next i
            Close intFile
            recPicture.Update
            Set recPicture = Nothing
        End If
    End Sub
      

  3.   

    to: jakenIT(漫步者) 
    你的方案有错,至少你的rs有问题,如果不在open中设置光标类型,和打开方式的话,会出错
      

  4.   

    还有哦,你的声明用as ,而不是用as new,能否给我一个详尽的