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!
Related
I am using the ComponentOne Winforms suite, specifically the FlexReport control, to generate output which will be sent directly to one of several printers. This isn't, I believe, an issue with the ComponentOne suite as I was having similar issues with Crystal.
The end result will run as a VB .Net windows service, but I am having real problems getting it to work. The current code is as follows:
Dim factory As New DatabaseProviderFactory()
Dim sysDb As SqlDatabase
Dim dsOrderList As New DataSet
Dim dsOrderDetail As New DataSet
Dim frPicklist55 As New C1.Win.FlexReport.C1FlexReport
Dim p1 As C1.Win.FlexReport.ReportParameter
Dim options As C1PrintOptions = New C1PrintOptions()
options.PrinterSettings = New PrinterSettings()
options.PageSettings = New System.Drawing.Printing.PageSettings()
'options.PrinterSettings.PrinterName = "\\printsvr\printername"
'options.PrinterSettings.PrinterName = "\\\\printsvr\\printername"
options.PrinterSettings.PrinterName = "Printer1"
sysDb = factory.Create("sys")
dsOrderList = sysDb.ExecuteDataSet("sp_apispool_getorders")
For Each r In dsOrderList.Tables(0).Rows
dsOrderDetail = sysDb.ExecuteDataSet("sp_apispool_getorder", r("order_no"))
frPicklist55.Load("D:\API Spooling Docs\Rpt55Picklist.flxr", "Picklist")
frPicklist55.Parameters("OrderNo").Value = r("order_no")
frPicklist55.Render()
frPicklist55.Print(options)
Next
Specifically, the issues are:
If I use a shared printer ('\printsvr\printername' or '\\printsvr\printername'), I get an exception about the printer settings not being valid.
If I use the local printer ('Printer1'), I get an exception -'Operation is not supported'
This should be really simple, but I suspect I am missing something fundamental. No matter what I do I get an exception at the point I call the Print function.
Any ideas?
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 have created a report that is based on a business object - this works great. I am now trying to add a button that renders the report directly to PDF (in a winforms application).
I know what I need to do - in code I am creating a ReportViewer, setting the DataSource, specifying the report (it's an embedded resource), then rendering the report into a byte array before using System.IO.File.WriteAllBytes to flush the byte array to disk. One thing I'm hung up on though, is how do I specify the instance of the object properly? I keep getting the "An error has occurred during the report processing" error. In IntelliTrace I can see that an exception is thrown "A data source instance has not been supplied for the data source 'IssRep'" (IssRep is the dataset name in the report. Here is the code:
Dim warning As Warning() = Nothing
Dim streamids As String() = Nothing
Dim mimetype As String = Nothing
Dim encoding As String = Nothing
Dim extension As String = Nothing
Dim viewer As New ReportViewer
Dim bs As New BindingSource
bs.DataSource = issuedet
Dim rds As New ReportDataSource
rds.Value = bs
viewer.LocalReport.DataSources.Add(rds)
viewer.ProcessingMode = ProcessingMode.Local
viewer.LocalReport.ReportEmbeddedResource = "FRSFE.SR.rdlc"
Dim pdfbytes As Byte()
Try
pdfbytes = viewer.LocalReport.Render("PDF", Nothing, mimetype, encoding, extension, streamids, warning)
File.WriteAllBytes("C:\Shared\FRS\SR.PDF", pdfbytes)
Catch ex As Exception
MsgBox(ex.Message)
End Try
I'm pretty sure whatever I'm stuck on is pretty simple as I'm very rusty on .NET but I just can't figure it out!
Try setting rds.Name = "IssRep" before adding it to viewer.LocalReport.DataSources.
on my .xsd file where I create the datatable for use in my Crystal Report (buit in with Visual Studio 2005), I have included a column (which is datatatype = 'Byte') that is supposed to hold the image for my crystal report.
However, there is always an error thrown at where I've typed COMMENT1, saying that the file is being used by another process. The file I am accessing is a mapped drive to our server.
when I try to ignore the error and press on continue, the report does show up..but without the image it was supposed to be with.
below is my complete syntax
Dim x As New Reporter
x.MdiParent = Magulang
Dim dt As New DataTable
dt.Columns.Add("EmpNo")
dt.Columns.Add("FullName")
dt.Columns.Add("Project")
dt.Columns.Add("SSS")
dt.Columns.Add("TIN")
dt.Columns.Add("EmergencyPerson")
dt.Columns.Add("EmergencyAddress")
dt.Columns.Add("EmergencyContact")
dt.Columns.Add("PicNya", System.Type.[GetType]("System.Byte[]"))
Dim middleinitial As String = MiddleName.Text.Substring(0, 1)
Dim fs As FileStream
Dim br As BinaryReader
If File.Exists(PicPath.Text) Then
'COMMENT1 : there is error here, saying that file is used by another process
fs = New FileStream(PicPath.Text, FileMode.Open)
Else
fs = New FileStream(AppDomain.CurrentDomain.BaseDirectory + "NoPhoto.jpg", FileMode.Open)
End If
br = New BinaryReader(fs)
Dim imgbyte As Byte() = New Byte(fs.Length) {}
imgbyte = br.ReadBytes(Convert.ToInt32((fs.Length)))
MsgBox(imgbyte.ToString)
dt.Rows.Add(EmpID.Text, FirstName.Text & " " & middleinitial & ". " & LastName.Text, Project.Text, SSS.Text, TIN.Text, EmergencyContact.Text, "", EmergencyContactNo.Text, imgbyte)
br.Close()
fs.Close()
Dim rptdoc As CrystalDecisions.CrystalReports.Engine.ReportDocument
rptdoc = New HRISID1
rptdoc.SetDataSource(dt)
x.CrystalReportViewer1.ReportSource = rptdoc
ProgressForm.Hide()
x.Show()
What can I do to resolve COMMENT1? if resolved, will the image finally output in my crystal report? Am I on the right track, if I wanted to output images on my computer?
For now, we have resolved to instead pass each Data into a seperate form, then use the PRINTFORM object included with the VB Powerpacks. This is to make sure the image is also printed.
I can't help but feel this isn't the proper solution though, so if anyone can still contribute it's very much welcome.
I want to get the following working, please could someone advise...
Dim rpt As ReportDocument
If (Exists(rpt.ReportDefinition.ReportObjects("crlTitle"))) Then
txtTitle = CType(rpt.ReportDefinition.ReportObjects("crlTitle"), TextObject)
txtTitle.Color = mainColour
txttitle.Text = "Report Title"
End If
Any help much appreciated.
I've never done anything like that...I'm not sure if it's possible. What will work for sure though is to use a parameter to control the report title. Simply create a parameter and then rpt.SetParamterValue("title", "Some Title")
Since you've identified the problem as "Exists is undefined". Addressing that problem is more straightforward. Try replacing the "Exists" line with:
If (rpt.ReportDefinition.ReportObjects.Contains("crlTitle")) Then
Were there any other problems?
Here is my solution:
Dim rpt as ReportDocument
Dim rptTextObject as TextObject = nothing
Dim mainColour As Color = Color.Green
Try
If (rpt.ReportDefinition.ReportObjects("crlTitle") IsNot Nothing) Then
rptTextObject = CType(rpt.ReportDefinition.ReportObjects("crlTitle"), TextObject)
rptTextObject.Color = mainColour
rptTextObject.Text = "Report Title"
End If
Catch
End Try
I do this for each Object on the report that I want to either set text or set colour.
Put this line of code at the beginning of the module
Imports System.IO.File