Solved

ImgEdit display via SQL - urgent

Posted on 2002-03-21
12
178 Views
Last Modified: 2008-02-01
Hi there

I'm trying to use the imaging control on a vb form. I can get the control to work via a fixed file location ie(C:\test.gif"). However I want the source to be a BLOB from a SQL database.

This is what I have so far.......

    objRS.Open "SELECT Data FROM Test", cnxn, adOpenKeyset, adLockOptimistic
   
    mstream.Type = adTypeBinary
    mstream.Open
   
    mstream.Write objRS.Fields("Data").Value
           
    frmControl.ImgEdit1.Image = mstream.Read
    frmControl.ImgEdit1.Display

But it errors out........on the mstream.read line

Is this possible or do I have to write the file out, use it and then delete it?

Any help would be appreciated.

Many thanks

John

PS These are all the points I have available
0
Comment
Question by:john_son74
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +2
12 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 6886324
i believe you have to write the file out to a temp file and then delete it.
0
 

Author Comment

by:john_son74
ID: 6886608
Hi bobbit31

How would I write it out to a temp file?
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6886665
mstream.SaveToFile "<path>", adSaveCreateOverWrite
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:bobbit31
ID: 6886672
note: to delete the file simply do,

Kill "<path>"
0
 

Accepted Solution

by:
tanvirs earned 37 total points
ID: 6887032
If you have SQL-Server installed on your machine.
Find Sample in
C:\Program Files\Microsoft SQL Server\80\Tools\DevTools\Samples\ado\unzip_ado.exe

Unzip this file. You will find multiple Dir.
look for VB\employee\
Run Employee.vbp & you will find what you require.
Some of the code i am pasting it here for you.

Cheers
Tanvir.

---------------------------------------------------------
Private Function FillDataFields()
    On Error GoTo ErrHandler:
   
    Dim fld As ADODB.Field
    Dim byteChunk() As Byte
    Dim strNote As String
    Dim Offset As Long
    Dim Totalsize As Long
    Dim Remainder As Long
    Dim NumOfChuncks As Long
    Dim CurrentRecPos As Long
    Dim FieldSize As Long
    Dim FileNumber As Integer
    Const HeaderSize As Long = 78
    Const ChunkSize As Long = 100
    Const TempFile As String = "tempfile.tmp"
                   
    ' Initialize fields.
    txtEID.Text = ""
    txtLastName.Text = ""
    txtFirstName.Text = ""
    txtTitle.Text = ""
    txtCTitle.Text = ""
    txtBirthDate.Text = ""
    txtHireDate.Text = ""
    txtAddress.Text = ""
    txtCity.Text = ""
    txtRegion.Text = ""
    txtZipCode.Text = ""
    txtCountry.Text = ""
    txtHomePhone.Text = ""
    txtExtension.Text = ""
    txtNotes.Text = ""
    txtReportsTo.Text = ""
    Image1.Picture = Nothing
   
    ' Initialize employee name and record position.
    lblName.Caption = ""
    txtRecCnt = ""
             
    Set Flds = rs.Fields
   
    ' Display record position.
    txtRecCnt = Str(rs.AbsolutePosition) + " of " + Str(rs.RecordCount)
     
    ' Assign the CurrentRecPos value.
    CurrentRecPos = rs.AbsolutePosition
                     
    ' Display the employee data.
    For Each fld In Flds
        FieldSize = fld.ActualSize
        If FieldSize > 0 Then                                 ' Rule out the none possibility.
            Select Case fld.Name
                Case "EmployeeID"
                    txtEID.Text = Str(fld.Value)
                Case "LastName"
                    txtLastName.Text = fld.Value
                Case "FirstName"
                    txtFirstName.Text = fld.Value
                Case "Title"
                    txtTitle.Text = fld.Value
                Case "TitleOfCourtesy"
                    txtCTitle.Text = fld.Value
                Case "BirthDate"
                    txtBirthDate.Text = Str(fld.Value)
                Case "HireDate"
                    txtHireDate.Text = Str(fld.Value)
                Case "Address"
                    txtAddress.Text = fld.Value
                Case "City"
                    txtCity.Text = fld.Value
                Case "Region"
                    txtRegion.Text = fld.Value
                Case "PostalCode"
                    txtZipCode.Text = fld.Value
                Case "Country"
                    txtCountry.Text = fld.Value
                Case "HomePhone"
                    txtHomePhone.Text = fld.Value
                Case "Extension"
                    txtExtension.Text = fld.Value
                Case "Photo"
                    FileNumber = FreeFile
                    Open TempFile For Binary Access Write As FileNumber
                    Totalsize = FieldSize - HeaderSize          ' Substract it from the total size.
                    byteChunk() = fld.GetChunk(HeaderSize)      ' Get rid of the header.
                    NumOfChuncks = Totalsize \ ChunkSize
                    Remainder = Totalsize Mod ChunkSize
                    If Remainder > 0 Then
                        byteChunk() = fld.GetChunk(Remainder)
                        Put FileNumber, , byteChunk()
                    End If
                    Offset = Remainder
                    Do While Offset < Totalsize
                        byteChunk() = fld.GetChunk(ChunkSize)
                        Put FileNumber, , byteChunk()
                        Offset = Offset + ChunkSize
                    Loop
                    Close FileNumber
                    Image1.Picture = LoadPicture(TempFile)
                    Kill (TempFile)
                Case "Notes"
                    Totalsize = FieldSize / 2                   ' Becuase of being WChar
                    NumOfChuncks = Totalsize \ ChunkSize
                    Remainder = Totalsize Mod ChunkSize
                    If Remainder > 0 Then
                        strNote = fld.GetChunk(Remainder)
                    End If
                    Offset = Remainder
                    Do While Offset < Totalsize
                        strNote = strNote + fld.GetChunk(ChunkSize)
                        Offset = Offset + ChunkSize
                    Loop
                    txtNotes.Text = strNote
                Case "ReportsTo"
                    Dim FindString As String
                    FindString = "EmployeeID = " + Str(fld.Value)
                    rs.MoveFirst                                    ' Move to the first record to ensure a search for the whole records.
                    rs.Find FindString, 1, adSearchForward          ' Search for the whole records.
                    If rs.EOF = False Then                          ' Did find the match.
                        txtReportsTo.Text = rs!firstname + " " + rs!LastName
                    End If
                    rs.Move (CurrentRecPos - rs.AbsolutePosition)   ' Move back to the record before the search.
            End Select
        End If
    Next
   
    ' Display employee name.
    lblName.Caption = txtFirstName.Text + "  " + txtLastName.Text
   
    Exit Function
   
ErrHandler:
    MsgBox Err.Description, , "Error "
   
End Function
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6887103
tanvirs:
why did you propose that as an answer? i don't believe it provides any information that john_son doesn't already know. (and i believe i've already answered this question)

0
 

Expert Comment

by:tanvirs
ID: 6887137
No i am affriad not, you have not answered the question for john_son. I have given a perfect example you can also have a look at it.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6887157
> Image1.Picture = LoadPicture(TempFile)

The original question was asking if you had to save the blob data from the database to a tempfile and if so, how to do it. (i showed him that)

the above you posted does the same thing (ie. doesn't read the blob data directly from the database)
0
 

Expert Comment

by:tanvirs
ID: 6887440
Thats correct it will write to a file & then display it from the file. but have not explained how to write it to the file.
0
 

Author Comment

by:john_son74
ID: 6888102
Hi all

I just checked in..........

Tanvirs the code you gave is very good, but it still creates a temp file (which I think is going to be the only way....) and doesnt transpose directly from sql to the image control.

Thanks also Bobbit31 for your input.

Assuming that a temp file is the only way, I will split the points between you (sorry I dont have any more than 75 to give)

Appreciate your help

Thanks

john_son
0
 
LVL 16

Expert Comment

by:twalgrave
ID: 7753508
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in Community Support that this question is:
- split points tanvirs bobbit31
Please leave any comments here within the
next seven days.
0
 

Expert Comment

by:SpideyMod
ID: 7809846
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange


bobbit31 points for you at:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20480192.html
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Add a task in Outlook from access 11 43
Getting warning: You are about to delete 1 row(s) 9 61
Help me. 3 78
add criteria to query in VB, Access 2003 2 47
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question