Solved

Step-By-Step Method of creating Parameters in Crystal Reports 9 in ASP.NET 1.1 Visual Basic

Posted on 2009-05-06
27
460 Views
Last Modified: 2013-11-15
Dear all,

I am new to ASP.NET and am using ASP.NET 1.1 Visual Basic. I have created some reports using Crystal Reports 9. I have successfully designed reports without parameters. I have also designed reports with parameters for the Windows applications. I have however failed to know how to design parameters for the ASP.NET 1.1 application.

May someone give me a step-by-step method of how I can design such reports.

Secondly I wish also to Export such reports to different formats such as pdf, doc, htm, etc. Please give steps too.

Nduguyettu
0
Comment
Question by:nduguyettu
  • 17
  • 8
  • 2
27 Comments
 
LVL 9

Expert Comment

by:Deathrace
Comment Utility
0
 

Author Comment

by:nduguyettu
Comment Utility
Thanks for the link but I ve not been helped. I ve copied the code but when I execute I just get a blank page. Can you give me more details about what should appear on the aspx page, what should appear in the Page_Load, etc.

As I told you am new to ASP.NET and Crystal Reports.


Nduguyettu
0
 
LVL 9

Expert Comment

by:Deathrace
Comment Utility

Try this....some predefined user control and simple to use

http://www.codeproject.com/KB/vb/CrystalContrl.aspx
0
 

Author Comment

by:nduguyettu
Comment Utility
Thanks a lot but the link you referred me to is for a Windows Application not ASP.NET which am interested in.

Nduguyettu
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
0
 

Author Comment

by:nduguyettu
Comment Utility
Is it possible to be directed to a link that can give me simplified information similar to the attached file?


Nduguyettu


VBNET-Crystal-Reports-String-Par.doc
0
 

Author Comment

by:nduguyettu
Comment Utility
I managed to get some code that exports crystal reports to different formats which I incorporated into my application. The report displays well in the CrystalReportViewer but when I click the button to export, it returns the following error message.

Exception Details: CrystalDecisions.CrystalReports.Engine.LogOnException: Logon failed

Please advise me what I should do to solve the problem.

I have attached the entire code.

Nduguyettu


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

        BindReport()

    End Sub

    Sub BindReport()

        Dim con As New SqlClient.SqlConnection

        con.ConnectionString = "Server = localhost; database=ThreeWs; Trusted_Connection=yes"

        Dim com As New SqlClient.SqlCommand

        com.Connection = con

        com.CommandText = "Select * from GenTransactions" 'GenTransactions is a View

        com.CommandType = CommandType.Text
 

        Dim DA As New SqlClient.SqlDataAdapter

        DA.SelectCommand = com
 

        Dim DS As New xsdGenTransactions 'XML Schema for Dataset
 

        DA.Fill(DS, "GenTransactions")

        Dim Rpt As New rptGenTransactions

        Rpt.SetDataSource(DS)
 

        CrystalReportViewer1.DisplayGroupTree = False
 

        CrystalReportViewer1.ReportSource = Rpt
 

    End Sub
 

    Sub ExportReport()

        Dim oStream As New MemoryStream

        Dim Rpt As rptGenTransactions = New rptGenTransactions

        Dim diskOpts As CrystalDecisions.Shared.DiskFileDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions

        Select Case DropDownList1.SelectedItem.Text 'this contains the value of the selected export format.
 

            Case "Rich Text (RTF)"
 

                oStream = Rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.WordForWindows)

                Response.Clear()

                Response.Buffer = True

                Response.ContentType = "application/rtf"

                '--------------------------------------------------------------------

            Case "Portable Document (PDF)"
 

                oStream = Rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)

                Response.Clear()

                Response.Buffer = True

                Response.ContentType = "application/pdf"

                '--------------------------------------------------------------------

            Case "MS Word (DOC)"
 

                oStream = Rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.WordForWindows)

                Response.Clear()

                Response.Buffer = True

                Response.ContentType = "application/doc"

                '--------------------------------------------------------------------

            Case "MS Excel (XLS)"
 

                oStream = Rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.Excel)

                Response.Clear()

                Response.Buffer = True

                Response.ContentType = "application/vnd.ms-excel"

                '--------------------------------------------------------------------

        End Select 'export format

        Try

            Response.BinaryWrite(oStream.ToArray())

            Response.End()

        Catch err As Exception

            Response.Write("<BR>")

            Response.Write(err.Message.ToString)

        End Try

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        ExportReport()

    End Sub

Open in new window

0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
SInce you have started a new report you need to set the data source just as you do for the viewer.

mmlmcc
0
 

Author Comment

by:nduguyettu
Comment Utility
Dear mmlmcc,

May you show me in the above code where I should place the data source as you suggest.

Thanks,

Nduguyettu
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
I can't be sure since I have never written one in .Net

Probably before the SELECT statement

mlmcc
0
 

Author Comment

by:nduguyettu
Comment Utility
Can someone find a problem with procedure ExportReport. It is the one returning the error.

Nduguyettu

0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
There is no problem with ExportReport.  It is in the way you are setting it up.

mlmcc
0
 

Author Comment

by:nduguyettu
Comment Utility
How should I set it up? This is my problem. I am failing to see the problem.

Nduguyettu
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
0
 

Author Comment

by:nduguyettu
Comment Utility
Thanks mlmcc

The first link you referred to me is for Windows based applications where I have no problem.

The second link leads me to VS2005. Though am using VS2003 I will read through the document and see if it can help me.


Nduguyettu
0
 

Author Comment

by:nduguyettu
Comment Utility
Hello mlmcc,

I read through the pdf document you referred to me but I discovered that it for a later version of CrystalReportViewer for VS2005. I am using VS2003.

Nduguyettu
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
The basic ideas should be the same.

mlmcc
0
 

Author Comment

by:nduguyettu
Comment Utility
In the document they refer to the ReportExporter Control which does not exist in VS 2003, so the basic idea is different.

Nduguyettu
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
Did you look at the code methods starting on page 191?

mlmcc
0
 

Author Comment

by:nduguyettu
Comment Utility
I think I need someone to look at the above code and tell me where the problem arises that causes the Exception. Otherwise I ve read the book and failed to find a solution. If not I wish I could get a book specifically designed for Visual Studio 2003.

Nduguyettu
0
 

Author Comment

by:nduguyettu
Comment Utility
I have managed to get a solution to the part of the question regarding Exporting to other formats. Through continued searching I came across the attached code which solved the problem.

What I was really missing in my code which kept on returning the Exception was the DataSource.

Nduguyettu
The following Code shows how to convert a Crystal Report to MS Word.
 

'First Create a crystal Report.

'Drag and drop the Crystal Report Viewer in the form

'copy this code on top of the code
 

Imports System.Data

Imports System.Data.SqlClient

Imports CrystalDecisions.CrystalReports.Engine

Imports CrystalDecisions.Shared       
 

Private myDS As New Dataset1() ' Dataset you created.
 

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

    Dim rpt As New CrystalReport1() 'The report you created.        

    Dim myConnection As SqlConnection        

    Dim MyCommand As New SqlCommand()        

    Dim myDA As New SqlDataAdapter()        

    Try            

        myConnection = New SqlConnection("Data Source=localhost;Integrated Security=SSPI; Initial       Catalog=pubs;")            

        MyCommand.Connection = myConnection            

        MyCommand.CommandText = "SELECT * FROM authors"            

        MyCommand.CommandType = CommandType.Text            

        myDA.SelectCommand = MyCommand            

        myDA.Fill(myDS, "authors")            

        rpt.SetDataSource(myDS)            

        CrystalReportViewer1.ReportSource = rpt        

        Catch Excep As Exception            

              MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)        

       End Try    

End Sub   
 
 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click        

 'This Code is used to Convert to word document        

       Dim reportWord As New CrystalReport1() ' Report Name         

       Dim strExportFile As String = "d:\TestWord.doc"        

       reportWord.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile        

       reportWord.ExportOptions.ExportFormatType = ExportFormatType.WordForWindows        

       Dim objOptions As DiskFileDestinationOptions = New DiskFileDestinationOptions()        

       objOptions.DiskFileName = strExportFile        

       reportWord.ExportOptions.DestinationOptions = objOptions        

       reportWord.SetDataSource(myDS)        

       reportWord.Export()        

       objOptions = Nothing        

       reportWord = Nothing    

End Sub

Open in new window

0
 

Author Comment

by:nduguyettu
Comment Utility
I have attached here some code which when used to display a report after selecting a parameter from the Dropdown list, a blank screen is displyed.

I have also attached a screen shot for the blank screen

Nduguyettu


 Private Sub ReportPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReportPreview.Click

        Dim Rpt As rptSelectedAccount = New rptSelectedAccount

        Dim DS As New xsdGenTransactions

        '=================================================

        Dim myConnection As SqlConnection

        Dim MyCommand As New SqlCommand

        Dim myDA As New SqlDataAdapter
 
 

        myConnection = New SqlConnection("Data Source=localhost;Integrated Security=SSPI; Initial Catalog=ThreeWs;")

        MyCommand.Connection = myConnection

        MyCommand.CommandText = "SELECT * FROM GenTransactions"

        MyCommand.CommandType = CommandType.Text

        myDA.SelectCommand = MyCommand

        myDA.Fill(DS, "GenTransactions")
 

        Rpt.SetDataSource(DS)

        '============================
 
 

        Dim crParameterDiscreteValue As ParameterDiscreteValue
 

        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
 

        Dim crParameterFieldLocation As ParameterFieldDefinition
 

        Dim crParameterValues As ParameterValues
 

        ' Get the report parameters collection. 
 

        crParameterFieldDefinitions = Rpt.DataDefinition.ParameterFields
 

        ' Add a parameter value - START
 

        crParameterFieldLocation = crParameterFieldDefinitions.Item("AccountName")
 

        crParameterValues = crParameterFieldLocation.CurrentValues
 

        crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
 

        crParameterDiscreteValue.Value = cboAccount.SelectedItem.Text
 

        crParameterValues.Add(crParameterDiscreteValue)
 

        crParameterFieldLocation.ApplyCurrentValues(crParameterValues)
 
 

        ' Add a parameter value - END

     
 

        ' Set report's DataSource. Skip this step if your report is calling a 

        ' stored procedure direct in the report.

        

        

        CrystalReportViewer1.DisplayGroupTree = False
 

        ' Set CrystalReportViewer.ReportSource
 

        CrystalReportViewer1.ReportSource = Rpt

        CrystalReportViewer1.RefreshReport()

    End Sub

Open in new window

Screen3.bmp
0
 

Author Comment

by:nduguyettu
Comment Utility
My last comment has not been responded to, am still waiting for some comments.
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
RefreshReport generally dumps the existing parameters.  Try using ViewReport

mlmcc
0
 

Author Comment

by:nduguyettu
Comment Utility
May you give me more information on how to use ViewReport because it is not an option under CrystalReportsViewer.

Nduguyettu
0
 

Author Comment

by:nduguyettu
Comment Utility
I made a small modification that resulted into some output. I included a textbox on the web form into which I type a parameter value. On clicking the preview button the parameter information is displayed on the screen.

The code below is similar to the above code only that I replaced cboAccount.SelectedItem.Text with txtAccount.Text.

The question is why the information cannot be displayed using the dropdown list. It may not be possible for the user to know which parameter name one may need to use.

Nduguyettu
crParameterFieldLocation = crParameterFieldDefinitions.Item("AccountName")

 

        crParameterValues = crParameterFieldLocation.CurrentValues

 

        crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue

 

        crParameterDiscreteValue.Value = txtAccount.Text

Open in new window

0
 

Accepted Solution

by:
nduguyettu earned 0 total points
Comment Utility
I have managed to get a solution to the problem.

Nduguyettu
Private Sub ReportPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReportPreview.Click

        Dim Rpt As rptSelectedAccount = New rptSelectedAccount

        Dim DS As New xsdGenTransactions

        'Dim spath2 As String = Environment.CurrentDirectory

        '=================================================

        Dim con As SqlConnection

        Dim comm As New SqlCommand

        Dim DA As New SqlDataAdapter
 

        con = New SqlConnection("Data Source=localhost;Integrated Security=SSPI; Initial Catalog=ThreeWs;")

        comm.Connection = con

        comm.CommandText = "SELECT * FROM GenTransactions"

        comm.CommandType = CommandType.Text

        DA.SelectCommand = comm

        DA.Fill(DS, "GenTransactions")
 

        Rpt.SetDataSource(DS)

        '============================
 

        Dim crParameterDiscreteValue As ParameterDiscreteValue

        Dim crParameterFieldDefinitions As ParameterFieldDefinitions

        Dim crParameterFieldLocation As ParameterFieldDefinition

        Dim crParameterValues As ParameterValues
 

        ' Get the report parameters collection. 
 

        crParameterFieldDefinitions = Rpt.DataDefinition.ParameterFields
 

        ' Add a parameter value - START
 

        crParameterFieldLocation = crParameterFieldDefinitions.Item("AccountName")

        crParameterValues = crParameterFieldLocation.CurrentValues

        crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue

        crParameterDiscreteValue.Value = Trim(cboAccount.SelectedItem.Text)

        crParameterValues.Add(crParameterDiscreteValue)

        crParameterFieldLocation.ApplyCurrentValues(crParameterValues)
 

        ' Add a parameter value - END
 

        ' Set report's DataSource. Skip this step if your report is calling a 

        ' stored procedure direct in the report.

        

        

        CrystalReportViewer1.DisplayGroupTree = False
 

        ' Set CrystalReportViewer.ReportSource
 

        CrystalReportViewer1.ReportSource = Rpt

        CrystalReportViewer1.RefreshReport()
 

    End Sub

Open in new window

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Hello, In my precious Article  (http://www.experts-exchange.com/Database/Reporting/A_15280-Create-Project-in-Microstrategy-Part-I.html)we saw the Configuration part for Microstrategy which included Metadata Creation and DataSource Preparation as …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

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

12 Experts available now in Live!

Get 1:1 Help Now