Set datasource at runtime ActiveReports 10

Posted by: luca on 4 January 2023, 11:29 am EST

    • Post Options:
    • Link

    Posted 4 January 2023, 11:29 am EST

    I try to set datasource at runtime in my report of Activereports 10.

    i have this code :

    Sub ActiveReport_ReportStart

    Dim connectionString = “Data Source=PC\SQLEXPRESS;Initial Catalog=Contratti;Integrated Security=True”

    Dim con As SqlConnection = New SqlConnection(connectionString)
    con.Open()
    
    Dim _strSQL As String = "Select id , cod from customers"
    
    Dim _cm As New SqlClient.SqlCommand(_strSQL, con)
    
    Dim _dt As New DataTable
    Dim _da As New SqlClient.SqlDataAdapter(_cm)
    _da.Fill(_dt)
    _dt.TableName = "customers"
    Me.DataSource = _dt
    

    End Sub

    I have the error :

    localhost:52620

    Error: Report Script Compile Error on line 50 :

    ‘DataSource’ non è un membro di ‘Script.ReportScript’

    What can i control ?

    i’d like load my datatable at runtime and set it to the report .

    Thank you

  • Posted 5 January 2023, 7:02 am EST

    Hi Luca,

    To set your DataTable as the data source for your report within the report’s script you can assign your DataSource to the report object (using ‘rpt’ instead of ‘Me’).

    Refer to the following code snippet:

    rpt.DataSource = _dt;

    Please Note: ActiveReports 10 is a legacy version of ActiveReports and we no longer provide support for the same. You may download the latest version of ActiveReports i.e. ActiveReports 16 to enjoy many more new features, bug fixes, and prompt support. You may download the same from here Download ActiveReports [https://www.grapecity.com/activereportsnet/download] and try it free for the first 30 days!

    Please find attached a sample implementing DataTable as DataSource using Report Script in ActiveReports 16.

    Regards,

    Anand

    DataTableDataSource.zip

  • Posted 5 January 2023, 12:04 pm EST

    Perfect.

    i tried also to use a datatable already taken by another page.

    I tried to use

    _dt=Session(“DSDATA”).Tables(“Offert”)

    but “Session” in not accepted in my script

  • Posted 6 January 2023, 6:02 am EST

    Hi Luca,

    Could you elaborate on the error message you are getting?

    If you are getting The type or namespace name ‘Session’ could not be found (are you missing a using directive or an assembly reference? then you’ll need to add the NameSpace for your Session object using the Import statement in your report’s script.

    Please Note: ActiveReports 10 is a legacy version of ActiveReports and we no longer provide support for the same. You may download the latest version of ActiveReports i.e. ActiveReports 16 to enjoy many more new features, bug fixes, and prompt support. You may download the same from here Download ActiveReports [https://www.grapecity.com/activereportsnet/download] and try it free for the first 30 days!

    Regards,

    Anand

  • Posted 9 January 2023, 7:03 am EST - Updated 9 January 2023, 12:04 pm EST

    Hi ,

    in my web page i use

    Inherits System.Web.UI.Page

    and after

    _dt=Session(“DSDATA”).Tables(“Offert”).

    I don’t understand what is the reference i have to insert to use it in the script of the report in Sub ActiveReport_ReportStart

    to use the same command : Session(“DSDATA”).Tables(“Offert”)

  • Posted 10 January 2023, 7:16 am EST - Updated 10 January 2023, 7:24 am EST

    Hi Luca,

    Unfortunately, as the ‘Session’ is an object of a different class (Inherited from System.Web.UI.Page) you won’t be able to use the same object within your RPX report.

    However, if you want to assign a DataTable from your session at runtime, as a workaround, you may cast your RPX report into a SectionReport class and assign your DataTable from your ‘Session’ to the ‘SectionReport.DataSource’ property (All within the class inherited from System.Web.UI.Page), now you may use this report as per your requirements.

    Please find attached an ActiveReports 16 sample implementing the same.

    Please Note: ActiveReports 10 is a legacy version of ActiveReports and we no longer provide support for the same. You may download the latest version of ActiveReports i.e. ActiveReports 16 to enjoy many more new features, bug fixes, and prompt support. You may download the same from here Download ActiveReports [https://www.grapecity.com/activereportsnet/download] and try it free for the first 30 days!

    Regards,

    Anand

    WebViewer_ASP.NET_C.zip

  • Posted 12 January 2023, 11:01 am EST - Updated 12 January 2023, 12:40 pm EST

    cannot do it with Activereports 10 ?

    For me update now to 16 is a problem.

    I try to modify my code ( vb.net ) :

    Partial Public Class _report1

    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    Dim rpt As GrapeCity.ActiveReports.SectionReport = New GrapeCity.ActiveReports.SectionReport()

    Dim xtr As System.Xml.XmlTextReader = New System.Xml.XmlTextReader(Server.MapPath(“~\SectionReport.rpx”))

    rpt.LoadLayout(xtr)

    xtr.Close()

    Dim con As System.Data.OleDb.OleDbConnection = Nothing

    con = New System.Data.OleDb.OleDbConnection(“Provider=Microsoft.ACE.OLEDB.12.0;Data Source=” & Server.MapPath(“~\data\NWind.mdb”))

    con.Open()

    Dim dt As DataTable = New DataTable()

    Dim da As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(New System.Data.OleDb.OleDbCommand(“Select * from Customers”, con))

    da.Fill(dt)

    con.Close()

    rpt.DataSource = dt

    WebViewer1.Report = rpt

    End Sub

    End Class

    I have an error :

    Error BC30560 ‘SectionReport’ is ambiguous in the namespace ‘GrapeCity.ActiveReports’.

    in the line :

    Dim rpt As GrapeCity.ActiveReports.SectionReport = New GrapeCity.ActiveReports.SectionReport()

    what can i check?

  • Posted 13 January 2023, 12:20 am EST

    Hi Luca,

    >> cannot do it with Activereports 10 ?

    Unfortunately, ActiveReports 10 is a very old version of ActiveReports and is no longer supported. Thus, we’ll recommend you to download the latest version of ActiveReports i.e. ActiveReports 16 to enjoy many more new features, bug fixes, and prompt support. You may download the same from here Download ActiveReports [https://www.grapecity.com/activereportsnet/download] and try it free for the first 30 days!

    >> what can i check?

    From your error code ‘BC30560’ we have found that this error could be caused due to a duplicate DLL present in your bin folder, you may try deleting the bin folder and rebuilding your solution. You may learn more about the same from this StackOverflow post: https://stackoverflow.com/questions/899130/bc30560-default-aspx-is-ambiguous-in-the-namespace-asp.

    Regards,

    Anand

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels