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
473 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
ID: 24312727
0
 

Author Comment

by:nduguyettu
ID: 24313816
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
ID: 24314081

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

http://www.codeproject.com/KB/vb/CrystalContrl.aspx
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:nduguyettu
ID: 24316488
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
ID: 24317225
0
 

Author Comment

by:nduguyettu
ID: 24323029
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
ID: 24323828
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
ID: 24326225
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
ID: 24326363
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
ID: 24326600
I can't be sure since I have never written one in .Net

Probably before the SELECT statement

mlmcc
0
 

Author Comment

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

Nduguyettu

0
 
LVL 100

Expert Comment

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

mlmcc
0
 

Author Comment

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

Nduguyettu
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 24336167
0
 

Author Comment

by:nduguyettu
ID: 24347351
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
ID: 24356347
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
ID: 24356634
The basic ideas should be the same.

mlmcc
0
 

Author Comment

by:nduguyettu
ID: 24361176
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
ID: 24364357
Did you look at the code methods starting on page 191?

mlmcc
0
 

Author Comment

by:nduguyettu
ID: 24365239
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
ID: 24467502
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
ID: 24511631
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
ID: 24562985
My last comment has not been responded to, am still waiting for some comments.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 24568309
RefreshReport generally dumps the existing parameters.  Try using ViewReport

mlmcc
0
 

Author Comment

by:nduguyettu
ID: 24569312
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
ID: 24569474
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
ID: 24578460
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

829 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