I am using VB.net and Winforms reportviewer for showing the reports generated using SQL Server Reporting Service.
I want to trigger the print of the reportviewer from code behind. Please help me in doing the same.
Dim usern = WindowsIdentity.GetCurrent().Name.ToString()
rptViewer.ProcessingMode = ProcessingMode.Remote
rptViewer.ServerReport.ReportServerUrl = New Uri("http://myserver/Reportserver")
rptViewer.ServerReport.ReportPath = "/Management Reports/InvoicReport"
Dim parm As ReportParameter
parm = New ReportParameter("parInvoiceID", InvoiceID)
rptViewer.ServerReport.SetParameters(parm)
rptViewer.ServerReport.Refresh()
Me.rptViewer.RefreshReport()
Thanks in advance
on RenderingComplete event of rptViewer write below code
rptViewer.PrintDialog()
Related
I'm trying to learn my way around VS 2013 using VB.net and its Report Viewer. I want to know how to pass a string to a parameter basically. And hopefully move on to other methods/procedures. Anyway I have a problem with this particular code block:
With Me.ReportViewer1.LocalReport
.ReportPath = "C:\Users\Kim\Documents\Visual Studio 2013\Projects\Tests\Tests\Report1.rdlc"
.DisplayName = "Test Report"
.DataSources.Clear()
End With
Me.ReportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.Normal)
Dim rpT As New ReportParameter("rpTitle", "Huehuehue")
Dim rpD As New ReportParameter("rpDate", "This day")
Dim HeaderParams As ReportParameter() = {rpT, rpD}
For Each param As ReportParameter In HeaderParams
ReportViewer1.LocalReport.SetParameters(param)
Next
If I comment out Dim rpD As New ReportParameter("rpDate", "This day") and change this line Dim HeaderParams As ReportParameter() = {rpT}, the rpT part will show correctly on the report form. The result is relatively the same if I exclude rpT instead. If I use both I get a Some parameters or credentials have not been specified on my report. I've been hovering around Google for sometime now but nobody else seems to have this kind of problem.
Solved it. Apparently you had to declare it as New ReportParameter() in the SetParameters. I don't know how to use an array there. But then again I'd still need to list all the parameters, so that'd be redundant. If anybody can improve this that would be great.
ReportViewer1.LocalReport.SetParameters(New ReportParameter() {rpT, rpD})
This is how I send parameter values:
1) create a generic list of type ReportParameter
2) add your new parameters to the list with a parameter name and value and visibility
3) set the parameters for the LocalReport
Dim paramList As New Generic.List(Of ReportParameter)
paramList.Add(New ReportParameter("ReportTitle", stgReportTitle, True))
paramList.Add(New ReportParameter("ReportFooter", stgReportFooter, True))
Me.vwrReport.LocalReport.SetParameters(paramList)
Always works!
I am using this code to pass parameters to my crystal report, but in run time crystal report is showing text boxes to input parameters. please help me to solve this
Dim rpt As New RPT_Maintenance
rpt.SetDataSource(maintenanceDetailsTable)
rpt.SetParameterValue("datefrom", dtpDateFrom.Text)
rpt.SetParameterValue("dateto", DtpDateTo.Text)
rpt.SetParameterValue("cat", "All Vehicles")
FRM_ReportViewer.CrystelReportViewer.ReportSource = rpt
FRM_ReportViewer.ShowDialog()
FRM_ReportViewer.Dispose()
If the parameter box keep popping up, what you can do is on the page load of your crystal report viewer form, paste this:
Dim param1Fields As New ParameterFields
Dim param1Field As New ParameterField
Dim param1Range As New ParameterDiscreteValue
param1Field.ParameterFieldName = "TeamRoster"
param1Range.Value = Roster.cmbTeams.Text
param1Field.CurrentValues.Add(param1Range)
param1Fields.Add(param1Field)
CrystalReportViewer1.ParameterFieldInfo = param1Fields
You have to set Datasource to report before settings parameter like.
reportClass.SetDataSource(source);
reportClass.SetParameterValue("txtCompanyName", companyName);
viewer.SetReportSource(reportClass);
I'm creating a program in VB.net with Visual Studio and some forms use Crystal Reports to show PDF reports, but i'm having problems with database connection. VB.net code can access the databse without problems, but when a form shows a report it asks me for username and password and if i write them it fails to connect. The application and the reports share the same database and i use the same data to connect, but Crystal Reports fails. Can you help me?
Here's a snippet that I have that works (in C#, but should give you an idea of how I did it):
CrystalReportSource CrystalReportSource1 = new CrystalReportSource();
CrystalReportViewer CrystalReportViewer1 = new CrystalReportViewer();
CrystalReportViewer1.ReportSource = CrystalReportSource1;
CrystalReportViewer1.EnableParameterPrompt = false;
CrystalReportSource1.Report.FileName = "Report3.rpt";
CrystalReportSource1.EnableCaching = false;
CrystalReportSource1.ReportDocument.SetParameterValue(0, ponumber);
CrystalReportSource1.ReportDocument.SetParameterValue(1, receiptno);
TableLogOnInfo logOnInfo = new TableLogOnInfo();
logOnInfo.ConnectionInfo.ServerName = ConfigurationManager.AppSettings["WarehouseReportServerName"];
logOnInfo.ConnectionInfo.DatabaseName = ConfigurationManager.AppSettings["WarehouseReportDatabaseName"];
logOnInfo.ConnectionInfo.UserID = ConfigurationManager.AppSettings["WarehouseReportUserID"];
logOnInfo.ConnectionInfo.Password = ConfigurationManager.AppSettings["WarehouseReportPassword"];
TableLogOnInfos infos = new TableLogOnInfos();
infos.Add(logOnInfo);
CrystalReportViewer1.LogOnInfo = infos;
maindiv.Controls.Add(CrystalReportSource1);
maindiv.Controls.Add(CrystalReportViewer1);
CrystalReportViewer1.DataBind();
Although you said that you are using the designers, I 'll post some code that is working for me, maybe it will help you:
Dim cryRpt As New ReportDocument
Dim strReportPath As String = 'The Path of the rpt file
cryRpt.Load(strReportPath)
cryRpt.SetDataSource(Me.crData) 'crData is a datatable with data for the report
crvReport.ReportSource = cryRpt 'crvReport is the CrystalReportViewer in my form
Check if all fields exist in the data when you set in "SetDataSource"
I am new to Visual Basic. I am using VB Premium 2012.
Is there a way I can open/start up an exe file (not my app) with params. I know we can do it in batch coding using echo and stuff. Can it be done in vb?
I want to open up "app.exe" with params as "-login usernamehere passwordhere"
Try this
Dim pHelp As New ProcessStartInfo
pHelp.FileName = "YourApplication.exe"
pHelp.Arguments = "parameter1,parameter2"
pHelp.UseShellExecute = True
pHelp.WindowStyle = ProcessWindowStyle.Normal
Dim proc As Process = Process.Start(pHelp)
I hope this helps...
It's my code:
CrystalReportViewer1.Zoom(75)
Dim rpt As New CrystalReport1
rpt.RecordSelectionFormula = "{members.id} ='3232'"
CrystalReportViewer1.ReportSource = rpt
CrystalReportViewer1.Refresh()
It shows all records, I don't know why
Dim CrReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument
CrReport = New CrystalDecisions.CrystalReports.Engine.ReportDocument()
CrReport.Load(Application.StartupPath & "\CrystalReport1.rpt")
CrReport.SetDataSource("HERE YOUR DATASET USED IN DA DESIGN OF CRYSTALREPORT1.rpt")
CrystalReportViewer1.ReportSource = CrReport
CrReport.RecordSelectionFormula = "{members.id} ='3232'"
Your CRYSTALREPORT1.rpt must be located at \\BIN\DEBUG OF your appath and it must be almost created before. Like an object by the designer from Visual Studio... .. > ADD NEW ITEM > CR
You must create a CrystalReportDocument in Form report (desing view), and after that, the Visual Studio will display a window where you can choose a Class for CrystalReportDocument. Choose the Class related with the report.rpt, and then in the print event add this:
crystalReportDocument.Load(#"reports\report.rpt");
crystalReportDocument.RecordSelectionFormula = "{viewTable.IdTable}=1";
crystalReportDocument.PrintToPrinter(1, false, 0, 0);
viewTable is a view element in Data Base.
Many people are used to DATASET for all, but in many cases it's ridiculous.