Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: SQL Image Base64 in report Post Reply Post New Topic
Author Message
chudok
Groupie
Groupie


Joined: 18 May 2010
Online Status: Offline
Posts: 70
Quote chudok Replybullet Topic: SQL Image Base64 in report
     Posted: 09 Jul 2012 at 9:13am
I have seen articles that seem like it is possible to add an image that is in a SQL database (image is in the database) to a Crystal report. I currently am using 11.5.8.826.

Not sure where to even start with this. I am connecting directly to the SQL database from Crystal.

IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 10 Jul 2012 at 7:14am
Some of this depends on what format the image is (.jpg, .gif, .bmp, etc.).  I've done this with .jpg formatted images in the past.  You just pull the field into the report and it should set up correctly.
-Dell
IP IP Logged
chudok
Groupie
Groupie


Joined: 18 May 2010
Online Status: Offline
Posts: 70
Quote chudok Replybullet Posted: 10 Jul 2012 at 8:00am
I've tried that and it didn't work.  When I look at the SQL database it the content_type is image/jpeg.

I'm trying to add an image  - go to the format editor for the picture - picture tab - and add a BLOB there.  I just don't know how to write this out..... any ideas? 

I have this but Crystal Reports does not recognize this....


System.Convert.FromBase64String(Mid(System.Convert.ToBase64String(Fields!{photos.base64}.Value), 105))




Edited by chudok - 10 Jul 2012 at 9:43am
IP IP Logged
chudok
Groupie
Groupie


Joined: 18 May 2010
Online Status: Offline
Posts: 70
Quote chudok Replybullet Posted: 10 Jul 2012 at 10:12am
Ok - I am getting closer - I connected by OLE db instead and I can at least see the code for the image - I can't see the image yet..... how do I get that converted?
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 10 Jul 2012 at 10:26am
Hmmm.... I've never had problems getting the image to show through an OLEDb connection (or through a native Oracle connection, but you're not connecting to Oracle.)
It's been several years since I've worked in Crystal XI, so I'm not sure whether this will work....
 
1.  Put a "Picture" on your report.
2.  Right-click and select "Format Graphic..."
3.  Go to the Picture tab.
4.  This is the part that I'm not sure is in XI - If you have an option for "Graphic Location", click on its formula button and enter the field that your image is stored in.
 
Even if you do have Graphic Location, I'm not sure this will work as I suspect that it needs a file path to the image instead of an image field.
 
-Dell
 
IP IP Logged
chudok
Groupie
Groupie


Joined: 18 May 2010
Online Status: Offline
Posts: 70
Quote chudok Replybullet Posted: 11 Jul 2012 at 7:36am
Didn't work.   Unhappy I'll have to talk to developer who created the database to see what he thinks could be the issue..... unless someone knows of something that I am missing.
IP IP Logged
dresses1250
Newbie
Newbie
Avatar

Joined: 11 Jul 2012
Location: 阿鲁巴
Online Status: Offline
Posts: 1
Quote dresses1250 Replybullet Posted: 11 Jul 2012 at 8:44pm
I have this but Crystal Reports does not recognize this.... System.Convert.FromBase64String(Mid(System.Convert.ToBase64String (Fields!{photos.base64}.Value), 105)) Edited by chudok - Yesterday at 9:43am
________________________________________
led spot light    
http://www.ledlightssell.com/led-spotlight-c-231.html

IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 12 Jul 2012 at 2:21am

Your problems are probably stemming from the fact that it's a Base64 field and not an actual image field.  I don't think Crystal can appropriately read that style of data.

 
-Dell
IP IP Logged
chudok
Groupie
Groupie


Joined: 18 May 2010
Online Status: Offline
Posts: 70
Quote chudok Replybullet Posted: 12 Jul 2012 at 2:26am

Yea - this is what I received back from the developer.  I was under the impression at first we could do it right from the DB but, it looks like we have to do a little work to get it up and running.   Thank you for your help.  I wish it would of been that easy for me, but it looks like it can be done, just have to do a little extra work to get it to work.

See notes below....

Unfortunately, no matter how we save the images to the DB, you will always need some script to display it.  The way it currently is, you can use a simply SQL Function to decode your images from its Base64 encoding.  Here is an example:

 

CREATE FUNCTION [dbo].[base64_decode] (@base64_text VARCHAR(max)) RETURNS

VARBINARY(max)

    WITH SCHEMABINDING, RETURNS NULL ON NULL INPUT BEGIN

    DECLARE @x XML; SET @x = @base64_text

    RETURN @x.value('(/)[1]', 'VARBINARY(max)') END GO
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum