Setting datasource for an existing rdlc report & print directly to printer

  • Thread starter Thread starter Hugh Self Taught
  • Start date Start date
H

Hugh Self Taught

Guest
Hi Clever Gurus,

My brain is frazzled from all the reading without success. I have a report AllPointsReport whose data is derived from a stored procedure. I'm able to print the report using the reportviewer. Now I've added functionality to filter the query & I need to print the filtered report to a pdf file (In some cases I will also email it)

Viewing Report Data shows my datasources as "PointsHistory" & the datasets as "PointsDataSet1". Viewing the reportviewer frmAllPointsViewerRpt has the following code

Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container()
Dim ReportDataSource1 As Microsoft.Reporting.WinForms.ReportDataSource = New Microsoft.Reporting.WinForms.ReportDataSource()
Me.stpPointsHistoryReportDataBindingSource = New System.Windows.Forms.BindingSource(Me.components)
Me.PointsHistory = New Sadta_Points_System.PointsHistory()
Me.ReportViewer1 = New Microsoft.Reporting.WinForms.ReportViewer()
Me.stpPointsHistoryReportDataTableAdapter = New Sadta_Points_System.PointsHistoryTableAdapters.stpPointsHistoryReportDataTableAdapter()
CType(Me.stpPointsHistoryReportDataBindingSource, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.PointsHistory, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'stpPointsHistoryReportDataBindingSource
'
Me.stpPointsHistoryReportDataBindingSource.DataMember = "stpPointsHistoryReportData"
Me.stpPointsHistoryReportDataBindingSource.DataSource = Me.PointsHistory
'
'PointsHistory
'
Me.PointsHistory.DataSetName = "PointsHistory"
Me.PointsHistory.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema
'
'ReportViewer1
'
ReportDataSource1.Name = "PointsDataSet1"
ReportDataSource1.Value = Me.stpPointsHistoryReportDataBindingSource
Me.ReportViewer1.LocalReport.DataSources.Add(ReportDataSource1)
Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "Sadta_Points_System.AllPointsReport.rdlc"
Me.ReportViewer1.Location = New System.Drawing.Point(-5, 0)
Me.ReportViewer1.Name = "ReportViewer1"
Me.ReportViewer1.Size = New System.Drawing.Size(1066, 791)
Me.ReportViewer1.TabIndex = 0
'
'stpPointsHistoryReportDataTableAdapter
'
Me.stpPointsHistoryReportDataTableAdapter.ClearBeforeFill = True


Currently I have these fragments of code from my experimenting

Dim lr As LocalReport = New LocalReport

'lr.ReportPath = "Sadta_Points_System.AllPointsReport.rdlc"
lr.ReportEmbeddedResource = "Sadta_Points_System.AllPointsReport.rdlc"

Dim tadapt As PointsHistoryTableAdapters.stpPointsHistoryReportDataTableAdapter = New PointsHistoryTableAdapters.stpPointsHistoryReportDataTableAdapter

Dim ds1 As ReportDataSource = New ReportDataSource("stpPointsHistoryReportData", ta1.Fill(dt))

lr.DataSources.Add(ds1)

Dim warnings() As Warning
Dim streamids() As String
Dim mimeType As String
Dim encoding As String
Dim extension As String
Dim bytes() As Byte = lr.Render("PDF", Nothing, mimeType, encoding, extension, streamids, warnings)
'Dim s As MemoryStream = New MemoryStream(bytes)
's.Seek(0, SeekOrigin.Begin)
Dim savepath As String = "d:\rdlc_rep.pdf"
' The FileStream class is in the System.IO namespace.
'Dim bytes() As Byte = Report.Render(fileType)
Dim fs As FileStream = New FileStream(savePath, FileMode.Create)
fs.Write(bytes, 0, bytes.Length)
fs.Close()



Can somebody please help me put the correct bits together so I can get this to work. I think I'm at a point of too much info overload & can't figure it out.

Continue reading...
 
Back
Top