Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2005
    Posts
    18

    Unhappy Unanswered: Hanling image data type columns

    Hi
    I have a table with image data type column. I would like to store photos (images in .jpg format) in the table. I am using ADODC to connect VB.NET with MS-SQL server 2000.

    Thanzzzzzzzzzz...

  2. #2
    Join Date
    Aug 2003
    Location
    Delft, The Netherlands (EU)
    Posts
    447
    Nobody is answering you, so here are two functions of my own library, doing the job. There are some references to other functions of mine, you will have to replace them. The idea of the functions is to write them temporarily to disk, and to use LoadPicture statements:
    Code:
    Public Function ShowBitmap(PictFld As ADODB.Field, PictLen As Long) As String
    Dim Buffer() As Byte
    Dim File_Num As Integer, File_Name As String
    Dim BlockCounter As Long
    
      Screen.MousePointer = vbHourglass
      DoEvents
    
      ' Get a temporary file name.
      File_Name = CoH.DBAux.TemporaryFileName()
      File_Num = FreeFile
      Open File_Name For Binary As #File_Num
    
      ' Copy the data into the file.
      For BlockCounter = 1 To Int(PictFld.ActualSize / BLOCK_SIZE)
          Buffer() = PictFld.GetChunk(BLOCK_SIZE)
          Put #File_Num, , Buffer()
      Next BlockCounter
    
      If PictFld.ActualSize Mod BLOCK_SIZE > 0 Then
          Buffer() = PictFld.GetChunk(PictFld.ActualSize Mod BLOCK_SIZE)
          Put #File_Num, , Buffer()
      End If
    
      Close #File_Num
      Screen.MousePointer = vbDefault
    
      Let ShowBitmap = File_Name
    End Function
    
    Public Function SaveBitmap(ByRef IRS As ADODB.Recordset, ByVal AbsPos As Long, ByRef PicBox As PictureBox) As String
    Dim File_Num As String
    Dim Buffer() As Byte
    Dim BlockCounter As Long
    
      With frmMDI.DlgCmd1
        .Flags = _
            cdlOFNFileMustExist Or _
            cdlOFNHideReadOnly Or _
            cdlOFNExplorer
        .CancelError = True
        .Filter = "Graphics Files|*.bmp;*.ico;*.jpg;*.gif"
    
        On Error Resume Next
        .ShowOpen
        If Err.Number = cdlCancel Then
            Exit Function
        ElseIf Err.Number <> 0 Then
            Select Case ShowError
            Case vbYes
              Resume Next
            Case vbNo
            Case vbCancel
              Debug.Assert False
              Resume
            End Select
            Exit Function
        End If
    
        ' Open the picture file.
        File_Num = FreeFile
        Open .FileName For Binary Access Read As #File_Num
        PicBox.Picture = LoadPicture(.FileName)
        
        SaveBitmap = CoH.DBAux.GetNthField(CoH.DBAux.GetNthField(.FileName, -1, "\"), 1, ".")
      End With
      
      Let IRS!IconLength = LOF(File_Num)
      If IRS!IconLength > 0 Then
        ReDim Buffer(BLOCK_SIZE)
        For BlockCounter = 1 To IRS!IconLength / BLOCK_SIZE
            Get #File_Num, , Buffer()
            IRS!IconImage.AppendChunk Buffer()
        Next BlockCounter
    
        If IRS!IconLength Mod BLOCK_SIZE > 0 Then
            ReDim Buffer(IRS!IconLength Mod BLOCK_SIZE)
            Get #File_Num, , Buffer()
            IRS!IconImage.AppendChunk Buffer()
        End If
    
        Close #File_Num
      End If
    End Function
    Make everything as simple as possible, but not simpler! - A. Einstein
    DB Problems? DB Explorer, BTrieve Re-engineering, DB Conversions & ETL? Conversion Tool

  3. #3
    Join Date
    Jan 2005
    Posts
    18
    Thanks a lot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •