Solved

How do display an image using VB 2005 / Crystal Reports for .Net 2.0

Posted on 2009-04-06
11
916 Views
Last Modified: 2012-05-06
Hello,  I've got a VB 2005 windows application that is pretty much just a shell for the crystal viewer.  The application is using Crystal Reports for .Net 2.0.  The application is designed to run from a command line and pass it parameters which will identify a certain report to run.  It also accepts parameters for the report itself.  I've developed a report using Crystal 11 that will pull some information from a database (Person's Name, address, phone #, etc...)  Inside the database is the path to an picture of the person.  I've embedded a "OLE Object" into the report and I pass it the path to where the picture of the person is located.  This works great in crystal 11 but when I pass that report to my application the picture does not show up.  It is just the OLE Object icon.  Does anyone know what the problem would be.  Does Crystal Reports for .Net 2.0 support dynamic images?  Any help would be greatly appreciated.

Thanks

Tim Morrow
0
Comment
Question by:UncleT
  • 5
  • 3
  • 3
11 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24081009
If you are trying to do that with the version of Crystal that is bundled with VS.Net, you have to pass the image as part of your dataset. See an example in http://www.emoreau.com/Entries/Articles/2006/10/Crystal-Reports--Part-II.aspx and http://www.emoreau.com/Entries/Articles/2006/09/Feeding-Crystal-Reports-from-your-application.aspx
0
 

Author Comment

by:UncleT
ID: 24081184
The crystal report is developed in Crystal 11.   The report will accept a parameter which is a database key to a "Personnel" table.  There is a field inside the Personnel Table that is a path to an image located on the server (\\servername\picture.jpg).  I load this path into the "Graphic Location" of the OLE Object.  The report runs fine in Crystal 11 but when I pass it to the crystal viewer that I created using VB 2005 and Crystal Reports for .net 2.0 it will not show the images.  Basically what the application I wrote does is displays the report.  

I Hope I am explaining it clear enough.
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24081222
>>but when I pass it to the crystal viewer that I created using VB 2005 and Crystal Reports for .net 2.0 it will not show the images

That feature is not supported in this version. You need to pass your image into a dataset
0
 

Author Comment

by:UncleT
ID: 24081479
Pardon me if I as stupid questions.  I am very new to .net programming and I am kind of just feeling my way around some of these applications.  I don't really understand what you are talking about when you say I need to put the image into a dataset.  In the VB application I am not creating any dataset for crystal.  Like I stated before, I use full blown Crystal 11 and I use ADO to access a SQL Server database to pull the data.  I basically pass the report a parameter and it will display in my viewer.  My application basically consists of the Crystal Viewer and a ReportDocument.

I am attaching the code that I use to display the report.

If I still have to pass the image using a dataset could you possibly explaing how.

Thanks in advance.

Tim Morrow
Public Class Crystal_Viewer
 

    Private Sub CRViewer_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
 

        Dim ep As New ErrParser
 

        Try
 

            Call g_s_Crystal_Shutdown()

            End
 

        Catch ex As Exception

            Dim ErrMsg As String

            ErrMsg = "Error in " & ep.GetProcName(ex.StackTrace)

            ErrMsg &= vbCrLf

            ErrMsg = ErrMsg & "Error Message: " & ex.Message

            MsgBox(ErrMsg, MsgBoxStyle.Exclamation Or MsgBoxStyle.OkOnly, "Application Error")

            End

        End Try
 

    End Sub
 

    Private Sub CRViewer_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
 

        Dim ep As New ErrParser
 

        Try

            'FIRED IF FORM IS CLOSED USING X IN CONTROL BOX
 

        Catch ex As Exception

            Dim ErrMsg As String

            ErrMsg = "Error in " & ep.GetProcName(ex.StackTrace)

            ErrMsg &= vbCrLf

            ErrMsg = ErrMsg & "Error Message: " & ex.Message

            MsgBox(ErrMsg, MsgBoxStyle.Exclamation Or MsgBoxStyle.OkOnly, "Application Error")

            End

        End Try
 

    End Sub
 

    Private Sub CRViewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 

        Dim int_ct As Integer

        Dim int_ct2 As Integer

        Dim str_Database As String = ""

        Dim bln_Security As Boolean

        Dim str_Server As String = ""

        Dim str_UserID As String = ""

        Dim str_Password As String = ""

        Dim str_Location As String = ""
 

        Call g_s_Crystal_OpenDatabase()
 

        g_str_SQL = ""

        g_str_SQL = g_str_SQL + "Select * " + vbCrLf

        g_str_SQL = g_str_SQL + "   from Crystal_Viewer_Reports" + vbCrLf

        g_str_SQL = g_str_SQL + "Where CV_Report_Parameter = '" + g_str_Parameter + "'" + vbCrLf
 

        Call g_s_Crystal_OpenSecRecords(g_str_SQL)
 

        If g_Crystal_Rs_DB.RecordCount = 0 Then

            MsgBox("Report not found in database for Parameter = " + g_str_Parameter)

            End

        Else

            If Len(Trim(g_str_Report_Description)) > 0 Then

                Me.Text = g_str_Report_Description

            Else

                Me.Text = g_Crystal_Rs_DB.Fields("CV_Report_Parameter").Value

            End If

        End If
 

        While Not g_Crystal_Rs_DB.EOF

            reportDocument1.FileName = g_Crystal_Rs_DB.Fields("CV_Report_Location").Value

            str_Location = g_Crystal_Rs_DB.Fields("CV_Report_Location").Value

            g_Crystal_Rs_DB.MoveNext()

        End While
 

        Call m_s_Load_Parameters()
 

        int_ct = reportDocument1.DataSourceConnections.Count

        For int_ct = 0 To reportDocument1.DataSourceConnections.Count - 1

            str_Database = reportDocument1.DataSourceConnections.Item(int_ct).DatabaseName.ToString

            bln_Security = reportDocument1.DataSourceConnections.Item(int_ct).IntegratedSecurity.ToString

            str_Server = reportDocument1.DataSourceConnections.Item(int_ct).ServerName.ToString

            str_UserID = reportDocument1.DataSourceConnections.Item(int_ct).UserID.ToString
 

            g_str_SQL = ""

            g_str_SQL = g_str_SQL + "Select * " + vbCrLf

            g_str_SQL = g_str_SQL + "   from Crystal_Database_Info" + vbCrLf

            g_str_SQL = g_str_SQL + "Where Crystal_Server = '" + g_f_str_ReplaceQuote(str_Server) + "'" + vbCrLf

            g_str_SQL = g_str_SQL + "  and Crystal_Database = '" + g_f_str_ReplaceQuote(str_Database) + "'" + vbCrLf

            g_str_SQL = g_str_SQL + "  and Crystal_UserID = '" + g_f_str_ReplaceQuote(str_UserID) + "'" + vbCrLf
 

            Call g_s_Crystal_OpenSecRecords(g_str_SQL)
 

            If g_Crystal_Rs_DB.RecordCount = 0 Then

                g_str_Error = "Report Login Info Not Found In Crystal_Database" + vbCrLf + vbCrLf

                g_str_Error = g_str_Error + "    Server = " + str_Server + vbCrLf

                g_str_Error = g_str_Error + "    Database = " + str_Database + vbCrLf

                g_str_Error = g_str_Error + "    UserID = " + str_UserID + vbCrLf + vbCrLf

                g_str_Error = g_str_Error + "Please contact an Administrator!"

                g_str_Title = "Missing Crystal Database Info"

                g_int_Error = MessageBox.Show(g_str_Error, g_str_Title, MessageBoxButtons.OK)

                Exit Sub

            End If
 

            While Not g_Crystal_Rs_DB.EOF

                str_Password = g_Crystal_Rs_DB.Fields("Crystal_Password").Value.ToString

                g_Crystal_Rs_DB.MoveNext()

            End While
 

            reportDocument1.DataSourceConnections.Item(int_ct).SetConnection(str_Server, str_Database, str_UserID, str_Password)

        Next int_ct
 

        For int_ct = 0 To reportDocument1.Subreports.Count - 1

            For int_ct2 = 0 To reportDocument1.Subreports(int_ct).DataSourceConnections.Count - 1

                str_Database = reportDocument1.Subreports(int_ct).DataSourceConnections.Item(int_ct2).DatabaseName.ToString

                bln_Security = reportDocument1.Subreports(int_ct).DataSourceConnections.Item(int_ct2).IntegratedSecurity.ToString

                str_Server = reportDocument1.Subreports(int_ct).DataSourceConnections.Item(int_ct2).ServerName.ToString

                str_UserID = reportDocument1.Subreports(int_ct).DataSourceConnections.Item(int_ct2).UserID.ToString
 

                g_str_SQL = ""

                g_str_SQL = g_str_SQL + "Select * " + vbCrLf

                g_str_SQL = g_str_SQL + "   from Crystal_Database_Info" + vbCrLf

                g_str_SQL = g_str_SQL + "Where Crystal_Server = '" + g_f_str_ReplaceQuote(str_Server) + "'" + vbCrLf

                g_str_SQL = g_str_SQL + "  and Crystal_Database = '" + g_f_str_ReplaceQuote(str_Database) + "'" + vbCrLf

                g_str_SQL = g_str_SQL + "  and Crystal_UserID = '" + g_f_str_ReplaceQuote(str_UserID) + "'" + vbCrLf
 

                Call g_s_Crystal_OpenSecRecords(g_str_SQL)
 

                If g_Crystal_Rs_DB.RecordCount = 0 Then

                    g_str_Error = "Report Login Info Not Found In Crystal_Database" + vbCrLf + vbCrLf

                    g_str_Error = g_str_Error + "    Server = " + str_Server + vbCrLf

                    g_str_Error = g_str_Error + "    Database = " + str_Database + vbCrLf

                    g_str_Error = g_str_Error + "    UserID = " + str_UserID + vbCrLf + vbCrLf

                    g_str_Error = g_str_Error + "Please contact an Administrator!"

                    g_str_Title = "Missing Crystal Database Info"

                    g_int_Error = MessageBox.Show(g_str_Error, g_str_Title, MessageBoxButtons.OK)

                    Exit Sub

                End If
 

                While Not g_Crystal_Rs_DB.EOF

                    str_Password = g_Crystal_Rs_DB.Fields("Crystal_Password").Value.ToString

                    g_Crystal_Rs_DB.MoveNext()

                End While
 

                reportDocument1.Subreports(int_ct).DataSourceConnections.Item(int_ct2).SetConnection(str_Server, str_Database, str_UserID, str_Password)

            Next

        Next
 

        CR_Viewer.ReportSource = reportDocument1
 

        g_str_SQL = ""

        g_str_SQL = g_str_SQL + "Insert into Crystal_Viewer_Accessed_Reports" + vbCrLf

        g_str_SQL = g_str_SQL + "  Values (" + vbCrLf

        g_str_SQL = g_str_SQL + "          '" + str_Location + "'," + vbCrLf

        g_str_SQL = g_str_SQL + "          '" + Environment.MachineName + "'," + vbCrLf

        g_str_SQL = g_str_SQL + "          '" + Environment.UserName + "'," + vbCrLf

        g_str_SQL = g_str_SQL + "          '" + Format(Now, "Short Date") + " " + Format(Now, "HH:mm:ss") + "'" + vbCrLf

        g_str_SQL = g_str_SQL + "         )" + vbCrLf
 

        lng_PK_Return = g_f_lng_Crystal_Update_DB(g_str_SQL)
 

    End Sub
 

    Public Sub m_s_Load_Parameters()
 

        Dim int_Ct As Integer

        Dim int_Ct2 As Integer

        Dim bln_Parameter As Boolean
 

        Dim ep As New ErrParser
 

        Try
 

            bln_Parameter = False

            For int_Ct = 0 To reportDocument1.ParameterFields.Count - 1

                For int_Ct2 = 0 To UBound(g_str_Param_Name) - 1

                    If UCase(reportDocument1.ParameterFields(int_Ct).Name) = UCase(g_str_Param_Name(int_Ct2)) Then

                        'Automatically Passes Value To Report

                        reportDocument1.ParameterFields(int_Ct).CurrentValues.AddValue(CStr(g_str_Param_Value(int_Ct2)))

                        bln_Parameter = True

                    End If

                Next int_Ct2

            Next
 

            If bln_Parameter = False Then

                MsgBox("No parameter was passed to the report!!")

            End If
 

        Catch ex As Exception

            Dim ErrMsg As String

            ErrMsg = "Error in " & ep.GetProcName(ex.StackTrace)

            ErrMsg &= vbCrLf

            ErrMsg = ErrMsg & "Error Message: " & ex.Message

            MsgBox(ErrMsg, MsgBoxStyle.Exclamation Or MsgBoxStyle.OkOnly, "Application Error")

            End

        End Try
 

    End Sub
 

End Class

Open in new window

0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24083336
Haven't you said at some point that you are using the CR version that is bundled with VS.Net?
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 100

Expert Comment

by:mlmcc
ID: 24083689
What viewewr are you using?

The .Net viewer included with VS2005 is for CR10 which doesn't support the file/path in the database.  You need to include the viewer from CR XI.

http://devlibrary.businessobjects.com/businessobjectsxir2/en/en/CrystalReports_dotNET_SDK/crsdk_net_doc/doc/crsdk_net_doc/html/crconsetupdevviewersvirtualdirectory.htm

mlmcc
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
ID: 24083701
Do you have CR XI R2?
Check the Crystal version in HELP --> ABOUT CRYSTAL
CR XI R2 is version 11.5.xxx

mlmcc
0
 

Author Comment

by:UncleT
ID: 24097869
The version of crystal we are using is the version that came with ESRI.  It is version 11.0.0.1282. Does anyone know if there is a Crystal 11 control that can be used in VB 2005?  Any help would be appreciated.  
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 24101455
Yes there is but you need CR XI R2. Crystal had to make changes to CR XI to work under .Net 2.0 framework which VS2005 runs under.

mlmcc
0
 

Author Comment

by:UncleT
ID: 24101718
I just installed CR XI R2.  The version of crystal shows 11.5.8.826.  When I open my project in VB 2005 the Crystal Viewer version is 11.5.3700.0.  I can run the application and in the crystal report this person has about 10 pictures.  The file location is in the database so I use Graphic Location to point it to the right picture.  It runs fine in the Crystal 11 Developer but when I run it in the Viewer application the only picture that shows up it the default picture I initially put in the picture control.  Any Idea?  Am I doing something wrong?
0
 

Author Closing Comment

by:UncleT
ID: 31567193
Thanks MLMCC for your help.  I installed CR XI R2 but the version of crystal my application was referenced was still the 10x version.  I changed it to reference the 11.5.xxx version and all seems to be working well.  Thanks again.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now