If you want to generate crystal reports without using database tables, stored procedures, datasets but you want to generate reports with direct user inputs, for example printing receipts directly from user inputs, then here is your stop. It is all about using parameters. It is assumed you know how to generate reports with crystal reports.
Below is a simple procedure for you to do so.
To start with
Add a new crystal report document to your project by choosing a blank report. Also create a form and add a crystalreportviewer to it. Design your report by creating the needed parameters that the report will accept from the user. For example as shown below
Then add the method below to a click event. Don’t forget to do these imports
1. Imports CrystalDecisions.CrystalReports.Engine
2. Imports CrystalDecisions.Shared
Private Sub printfees()
Dim rpd As New ReportDocument
‘loading the report from a specified location
rpd.Load(Application.StartupPath & "\reports\rptPaymentReceipt.rpt")
‘assigning values to your report parameters
rpd.SetParameterValue("prog", Me.txtProgram.Text)
rpd.SetParameterValue("sname", Me.txtName.Text.Replace("–", "").Trim)
rpd.SetParameterValue("acadyear", "Year: " & Me.lblYear.Text & " Sem: " & Me.lblSemester.Text)
rpd.SetParameterValue("pdate", CDate(Me.dtpPaid.Value))
rpd.SetParameterValue("indexno", Me.txtIndexNo.Text)
rpd.SetParameterValue("ptype", Me.dspaytype.Rows(Me.cmbPaytype.SelectedIndex)(1).ToString)
‘frmReportsFace is a form with a crystalreportsviewer called crv1
Dim f As New frmReportsFace
f.crv1.ReportSource = rpd
‘below is a method to make your crystal reports independent on a ‘patrticular database server
SetDBLogonForReport(rpd)
f.Show()
End Sub
‘ a method that makes your crsystal reports independent on the database sever
Private Sub SetDBLogonForReport(ByVal myReportDocument As ReportDocument)
Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()
‘dbase is a class to return certain information about databases,
myConnectionInfo.DatabaseName = dbase.getDataname
myConnectionInfo.UserID = dbase.getUName
myConnectionInfo.Password = dbase.getdbasePassword
myConnectionInfo.ServerName = dbase.getServerName
myConnectionInfo.IntegratedSecurity = dbase.getIntegratedSecurity
myConnectionInfo.AllowCustomConnection = True
Dim myTables As Tables = myReportDocument.Database.Tables
For Each myTable As CrystalDecisions.CrystalReports.Engine.Table In myTables
Dim myTableLogonInfo As TableLogOnInfo = myTable.LogOnInfo
myTableLogonInfo.ConnectionInfo = myConnectionInfo
myTable.ApplyLogOnInfo(myTableLogonInfo)
Next
End Sub