This is a migrated thread and some comments may be shown as answers.

Accessing subroutine in report code

1 Answer 67 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
AnneArents
Top achievements
Rank 1
AnneArents asked on 06 Apr 2011, 10:38 AM
Hi,

I have a subroutine in my report that adds parameters to my sqldatasource:
Public Class SalesReport
    Inherits Telerik.Reporting.Report
    Public Sub New()
        InitializeComponent()
    End Sub
    Public Sub AddDataSourceParameter(ByVal sParameterNaam As String, ByVal tDBType As System.Data.DbType, ByVal oValue As Object)
        Me.SqlDataSource1.Parameters.Add(sParameterNaam, tDBType, oValue)
    End Sub
End Class

I want to call this subroutine from the webpage that I use to create a PDF from the report. (using the sample code from this website)
Sub ExportToBrowser(ByVal reportToExport As Telerik.Reporting.Report)
        Dim reportProcessor As New ReportProcessor()
        Dim result As RenderingResult = reportProcessor.RenderReport("PDF", reportToExport, Nothing)
 
        Dim fileName As String = result.DocumentName + ".pdf"
 
        Response.Clear()
        Response.ContentType = result.MimeType
        Response.Cache.SetCacheability(HttpCacheability.Private)
        Response.Expires = -1
        Response.Buffer = True
        Response.AddHeader("Content-Disposition", String.Format("{0};FileName=""{1}""", "attachment", fileName))
        Response.BinaryWrite(result.DocumentBytes)
        Response.End()
    End Sub
As you can see this is a generic function that only requires a Telerik report parameter.
So, in my code, I declare the report like this:
Dim report As Telerik.Reporting.Report = New ReportLib.SalesReport
However, this way I can't access my function 'AddDataSourceParameter'.
It only works if I declare it like this:
Dim report As ReportLib.SalesReport = New ReportLib.SalesReport
But this way I no longer have a generic report type to use in my ExportToPDF function.

Is there another way to do this?
(I'm not looking at another way to bind my parameters, but another way to access this sub. This is just an example)

Thanks,
CJ

1 Answer, 1 is accepted

Sort by
0
Squall
Top achievements
Rank 1
answered on 08 Apr 2011, 03:01 PM
Hi,
Can you do that with any .net types? When you are upcasting, you don't have access to the derived class method, because the runtime object is base type.  
http://www.c-sharpcorner.com/UploadFile/pcurnow/polymorphcasting06222007131659PM/polymorphcasting.aspx
http://bytes.com/topic/c-sharp/answers/214604-oo-upcasting-issue
Tags
General Discussions
Asked by
AnneArents
Top achievements
Rank 1
Answers by
Squall
Top achievements
Rank 1
Share this question
or