Hello!
I'm having an issue with VB 2010 and the report-viewer.
I have a form where I have placed a report viewer linked to a report (Report1.rdlc)
There is also a parameter.
What I want to do is to print automatically the report so the user don't have to press the printer icon.
But it only works if I don't use the parameter (although it appears right when I compile). The error I get is in the "
report.Render("Image", deviceInfo, AddressOf CreateStream, warnings)
"
ONE OR MORE PARAMETERS NEED TO BE SPECIFIED.... (more or less as it's in spanish)
Here's the code. Hope someone can help
HOW CAN I PASS THERE PARAMETERS TO THE RENDER METHOD??
oscarsaez1975@hotmail.com
"
Imports System.Data.SqlClient
Imports Microsoft.Reporting.WinForms
Imports System.IO
Imports System.IO.Stream
Imports System.Data
Imports System.Text
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Drawing.Printing
Imports System.Collections.Generic
Imports System.Windows.Forms
Public Class Form1
Implements IDisposable
Public m_currentPageIndex As Integer
Public m_streams As IList(Of Stream)
Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim params(1) As Microsoft.Reporting.WinForms.ReportParameter
params(0) = New Microsoft.Reporting.WinForms.ReportParameter("reportTitle", "Hola")
params(1) = New Microsoft.Reporting.WinForms.ReportParameter("reportFile", "MAS")
ReportViewer1.LocalReport.SetParameters(params)
Me.ReportViewer1.RefreshReport()
End Sub
Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Run()
End Sub
Public Function LoadSalesData() As DataTable
Dim dataSet As New DataSet()
dataSet.ReadXml("data.xml")
Return dataSet.Tables(0)
End Function
Public Function CreateStream(ByVal name As String, _
ByVal fileNameExtension As String, _
ByVal encoding As Encoding, ByVal mimeType As String, _
ByVal willSeek As Boolean) As Stream
Dim stream As Stream = New FileStream(name + "." + fileNameExtension, FileMode.Create)
m_streams.Add(stream)
Return stream
End Function
Public Sub Export(ByVal report As LocalReport)
Dim deviceInfo As String =
"<deviceinfo>" + _
" <outputformat>EMF</outputformat>" + _
" <pagewidth>8.5in</pagewidth>" + _
" <pageheight>11in</pageheight>" + _
" <margintop>0.25in</margintop>" + _
" <marginleft>0.25in</marginleft>" + _
" <marginright>0.25in</marginright>" + _
" <marginbottom>0.25in</marginbottom>" + _
"</deviceinfo>"
Dim warnings() As Warning = Nothing
m_streams = New List(Of Stream)()
report.Render("Image", deviceInfo, AddressOf CreateStream, warnings)
Dim stream As Stream
For Each stream In m_streams
stream.Position = 0
Next
End Sub
Public Sub PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
Dim pageImage As New Metafile(m_streams(m_currentPageIndex))
ev.Graphics.DrawImage(pageImage, ev.PageBounds)
m_currentPageIndex += 1
ev.HasMorePages = (m_currentPageIndex < m_streams.Count)
End Sub
Public Sub Print()
Const printerName As String = "\\Printserver\RICOH Aficio MPC2500_MAT"
If m_streams Is Nothing Or m_streams.Count = 0 Then
Return
End If
Dim printDoc As New PrintDocument()
printDoc.PrinterSettings.PrinterName = printerName
If Not printDoc.PrinterSettings.IsValid Then
Dim msg As String = String.Format("Can't find printer ""{0}"".", printerName)
Debug.WriteLine(msg)
Return
End If
AddHandler printDoc.PrintPage, AddressOf PrintPage
printDoc.Print()
End Sub
Public Sub Run()
Dim report As LocalReport = New LocalReport()
report.ReportPath = "Report1.rdlc"
report.DataSources.Add(New ReportDataSource("Sales", LoadSalesData()))
report.GetParameters()
Export(report)
m_currentPageIndex = 0
Print()
End Sub
Public Overloads Sub Dispose() Implements IDisposable.Dispose
If Not (m_streams Is Nothing) Then
Dim stream As Stream
For Each stream In m_streams
stream.Close()
Next
m_streams = Nothing
End If
End Sub
End Class
"