Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / COM / May 2005



Tip: Looking for answers? Try searching our database.

Problem with retrieving Picture

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Madhivanan - 26 May 2005 10:25 GMT
I have an Access database table with OLE object column(Already having
many data). I used AppenChunk method to retrieve the picture. The
problem is that If I add records, then I can retrieve the pictures. But
already stored pictures are not retrieved, giving invalid picture
error. How can I solve this?

Madhivanan
Norm Cook - 26 May 2005 14:26 GMT
Hard to say without seeing your code.  However,

> many data). I used AppenChunk method to retrieve the picture. The

Shouldn't you be using GetChunk to retrieve?

> I have an Access database table with OLE object column(Already having
> many data). I used AppenChunk method to retrieve the picture. The
[quoted text clipped - 3 lines]
>
> Madhivanan
Madhivanan - 26 May 2005 14:37 GMT
yes i used GetChunk method

Here is the code
   sSQL = "select * from images"
       sSQL = "select task1 from t_tasks"

       Set rsImage = New ADODB.Recordset

       rsImage.CursorType = adOpenDynamic
       rsImage.LockType = adLockOptimistic

       rsImage.Open sSQL, objDB
       If rsImage.BOF Then
       MsgBox ("No records in Database")
       cmdnext.Enabled = False
       txtName.SetFocus
       Exit Sub
       End If
       '''txtName.Text = rsImage("name")
       '''txtdesig.Text = rsImage("Designation")
       '''txttitle.Text = rsImage("Title")
          ''' txtpno.Text = rsImage("Phoneno")

       If Not rsImage.EOF Then
           nHandle = FreeFile
           sPath = App.Path
           sFile = sPath & "\output.bin"

           Open sFile For Binary Access Write As nHandle
           Set fld = rsImage("task1")
          lsize = rsImage("task1").ActualSize
          iChunks = lsize \ conChunkSize
          nFragmentOffset = lsize Mod conChunkSize

          varChunk() = rsImage("task1").GetChunk(nFragmentOffset)
          Put nHandle, , varChunk()
          lOffset = nFragmentOffset
          For i = 1 To iChunks
               ReDim varChunk(conChunkSize) As Byte
               varChunk() = rsImage("task1").GetChunk(conChunkSize)
               Put nHandle, , varChunk()

               DoEvents
          Next

End If
Close nHandle
Set Picture1.Picture = LoadPicture(sFile, , vbLPColor)

Any ideas?

Madhivanan
Norm Cook - 26 May 2005 16:51 GMT
Perhaps someone with more ADO experience can spot an error.
Personally, I use DAO and set the field type to Memo vice OLE Object.
Saving & retrieving pics if fairly straightforward with this method

Private Sub SavePic(ByVal FileName As String)
Dim filenum As Integer
Dim rst As Recordset
Dim str As String

'read the file into a string
filenum = FreeFile
Open FileName For Binary As #filenum
str = Space$(LOF(filenum))
Get #filenum, , str
Close #filenum

'add it to the DB table
Set rst = db.OpenRecordset("Table1")
rst.AddNew
rst("Data") = str
rst.Update
rst.Close
Set rst = Nothing
End Sub

Private Sub LoadPic()
Dim Dat As String
Dim rst As Recordset
Dim filenum As Integer
'read the DB pic data
Set rst = db.OpenRecordset("Table1")
rst.MoveFirst   'gets the 1st picture
Dat = rst.Fields("Data")
'write it out to a file
Open App.Path & "\work.jpg" For Binary As 1    'change ext as approp
Put #1, , Dat
Close 1
Picture1.Picture = LoadPicture(App.Path & "\work.jpg")
Kill App.Path & "\work.jpg"
Set rst = Nothing
End Sub

> yes i used GetChunk method
>
[quoted text clipped - 48 lines]
>
> Madhivanan
Wayne Right - 27 May 2005 08:24 GMT
Maybe following code helps;
'***** Code is extracted from my source code running on SQL Server.
'***** Dim mStream As New ADODB.Stream

   s = "SELECT STOK_IMAGE FROM STOK_RESIM WHERE STOK_KODU = 'AAA'"
   ReadData s, True

   With mStream
       .Type = adTypeBinary
       .Open
       .Write rAdoRs.Fields(0).Value
       .SaveToFile sFName, adSaveCreateOverWrite
   End With
   Image1.Picture = LoadPicture(sFName)

   Set mStream = Nothing

>I have an Access database table with OLE object column(Already having
> many data). I used AppenChunk method to retrieve the picture. The
[quoted text clipped - 3 lines]
>
> Madhivanan
Madhivanan - 27 May 2005 10:59 GMT
Wayne Right
I tried your method to save it in different formats(bmp,gif,jpg,tif)
But it says Invalid picture
How do I know the type of the picture?

Madhivanan
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.