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

Can't get parameter value in NeedDateSource event

5 Answers 264 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 11 Jun 2009, 02:57 PM
I am trying to pass a parameter to my data source, but it isn't passing the correct value.  How does my code look below?  Is there a way to debug and use breakpoints when building report classes?

namespace AWS_Reports 
    using System; 
    using System.ComponentModel; 
    using System.Drawing; 
    using System.Windows.Forms; 
    using System.Configuration; 
    using Telerik.Reporting; 
    using Telerik.Reporting.Drawing; 
 
    /// <summary> 
    /// Summary description for MyAccountEstimator. 
    /// </summary> 
    public partial class MyAccountEstimatorStats : Telerik.Reporting.Report 
    { 
        public MyAccountEstimatorStats() 
        { 
            /// <summary> 
            /// Required for telerik Reporting designer support 
            /// </summary> 
            InitializeComponent(); 
 
            // Remove the design time data source to force use of NeedDataSource event 
            this.DataSource = null
            lstSummary.DataSource = null
        } 
 
        private void MyAccountEstimatorStats_NeedDataSource(object sender, EventArgs e) 
        { 
            // Try to get connection string from config file 
            ConnectionStringSettings cnStr = cnStrSettings(); 
            if ((cnStr != null) && (cnStr.ConnectionString != null)) 
            { 
                this.dsEstimatorUsageDetailsTableAdapter1.Connection.ConnectionString = cnStrSettings().ConnectionString; 
            } 
            try 
            { 
                this.dsEstimatorUsageDetailsTableAdapter1.Fill(this.dsEstimatorUsage.dsEstimatorUsageDetailsTable, StartDate, EndDate); 
                this.DataSource = this.dsEstimatorUsage; 
                this.DataMember = "dsEstimatorUsageDetailsTable"
            } 
            catch (System.Exception ex) 
            { 
                // An error has occurred while filling the data set. Please check the exception for more information. 
                System.Diagnostics.Debug.WriteLine(ex.Message); 
            } 
        } 
 
        private void lstSummary_NeedDataSource(object sender, EventArgs e) 
        { 
            // Try to get connection string from config file 
            ConnectionStringSettings cnStr = cnStrSettings(); 
            if ((cnStr != null) && (cnStr.ConnectionString != null)) 
            { 
                this.prWEP_MyAccountUsageTotalsTableAdapter1.Connection.ConnectionString = cnStrSettings().ConnectionString; 
            } 
            try 
            { 
                 
                this.prWEP_MyAccountUsageTotalsTableAdapter1.Fill(this.dsEstimatorUsage.prWEP_MyAccountUsageTotals, StartDate, EndDate); 
                this.lstSummary.DataSource = this.dsEstimatorUsage; 
                this.lstSummary.DataMember = "prWEP_MyAccountUsageTotals"
            } 
            catch (System.Exception ex) 
            { 
                // An error has occurred while filling the data set. Please check the exception for more information. 
                System.Diagnostics.Debug.WriteLine(ex.Message); 
            } 
        } 
 
        private ConnectionStringSettings cnStrSettings() 
        { 
            // Get connection string from web.config 
            ConnectionStringSettings connStrSettings = ConfigurationManager.ConnectionStrings["AnchorWallConnectionString"]; 
            return connStrSettings; 
        } 
        public DateTime StartDate 
        { 
            get { return DateTime.Parse(this.ReportParameters["StartDate"].Value.ToString()); } 
 
            set { this.ReportParameters["StartDate"].Value = value; } 
        } 
 
        public DateTime EndDate 
        { 
            get { return DateTime.Parse(this.ReportParameters["EndDate"].Value.ToString()); } 
 
            set { this.ReportParameters["EndDate"].Value = value; } 
        } 
 
    } 

5 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 15 Jun 2009, 11:14 AM
Hi Brian,

As explained in the Understanding Events help topic, when you're in the context of an event, you should use the processing objects instead of the report definition ones e.g.:

Wrong:
this.DataSource = this.dsEstimatorUsage;
this.DataMember = "dsEstimatorUsageDetailsTable";

Correct:
Telerik.Reporting.Processing.Report procRpt = (Telerik.Reporting.Processing.Report)sender;
procRpt.DataSource = this.dsEstimatorUsage;
procRpt.DataMember = "dsEstimatorUsageDetailsTable";

You can debug by hooking up the report to a viewer in a win/web application and set this application as startup project.

All the best,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Brian
Top achievements
Rank 1
answered on 15 Jun 2009, 03:36 PM
Okay, I got it working for the main section of my report by using the casted sender object.  But how do I do that for my List lstSummary item that uses the same DataSource but a different data member.The sender would be the List object, I think.  And it errors on the cast of lSum.Report
Do I have to make this into a subreport?
        private void MyAccountEstimatorStats_NeedDataSource(object sender, EventArgs e)  
        {  
            // Try to get connection string from config file  
            ConnectionStringSettings cnStr = cnStrSettings();  
            if ((cnStr != null) && (cnStr.ConnectionString != null))  
            {  
                this.dsEstimatorUsageDetailsTableAdapter1.Connection.ConnectionString = cnStrSettings().ConnectionString;  
            }  
            try 
            {  
                Telerik.Reporting.Processing.Report procRpt = (Telerik.Reporting.Processing.Report)sender;  
                  
                this.dsEstimatorUsageDetailsTableAdapter1.Fill(this.dsEstimatorUsage.dsEstimatorUsageDetailsTable, (DateTime)procRpt.Parameters["StartDate"], (DateTime)procRpt.Parameters["EndDate"]);  
                procRpt.DataSource = this.dsEstimatorUsage;  
                procRpt.DataMember = "dsEstimatorUsageDetailsTable";  
            }  
            catch (System.Exception ex)  
            {  
                // An error has occurred while filling the data set. Please check the exception for more information.  
                System.Diagnostics.Debug.WriteLine(ex.Message);  
            }  
        }  
 
        private void lstSummary_NeedDataSource(object sender, EventArgs e)  
        {  
            // Try to get connection string from config file  
            ConnectionStringSettings cnStr = cnStrSettings();  
            if ((cnStr != null) && (cnStr.ConnectionString != null))  
            {  
                this.prWEP_MyAccountUsageTotalsTableAdapter1.Connection.ConnectionString = cnStrSettings().ConnectionString;  
            }  
            try 
            {  
                Telerik.Reporting.List lSum = (Telerik.Reporting.List)sender;  
                Telerik.Reporting.Processing.Report procRpt = (Telerik.Reporting.Processing.Report)lSum.Report;  
 
                this.prWEP_MyAccountUsageTotalsTableAdapter1.Fill(this.dsEstimatorUsage.prWEP_MyAccountUsageTotals, DateTime.Now.AddMonths(-6), DateTime.Now);  
                lSum.DataSource = this.dsEstimatorUsage;  
                lSum.DataMember = "prWEP_MyAccountUsageTotals";  
            }  
            catch (System.Exception ex)  
            {  
                // An error has occurred while filling the data set. Please check the exception for more information.  
                System.Diagnostics.Debug.WriteLine(ex.Message);  
            }  
        } 
0
Steve
Telerik team
answered on 16 Jun 2009, 07:12 AM
Hello Brian,

The list as a separate report item has its processing counterpart i.e. the cast should be:

Telerik.Reporting.Processing.List lSum = (Telerik.Reporting.Processing.List)sender;
lSum.DataSource = this.dsEstimatorUsage; 
lSum.DataMember = "prWEP_MyAccountUsageTotals";

Best wishes,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Brian
Top achievements
Rank 1
answered on 16 Jun 2009, 05:11 PM
My Telerik.Reporting.Processing namespace doesn't have a List object.  I see all the other report items like textbox, chart, etc.  But no List object.  I am using 2009 Q1 SP1.
0
Accepted
Steve
Telerik team
answered on 17 Jun 2009, 07:28 AM
Hello Brian,

I am sorry for the confusion created, I just copy pasted your code and modified it accordingly without giving it much thought. Actually the processing object is Table (the Table, Crosstab and List items are actually the same Table item with different initial settings as explained here). So the code should be:

Telerik.Reporting.Processing.Table lSum = (Telerik.Reporting.Processing.Table)sender;
lSum.DataSource = this.dsEstimatorUsage;
lSum.DataMember = "prWEP_MyAccountUsageTotals";

Greetings,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
General Discussions
Asked by
Brian
Top achievements
Rank 1
Answers by
Steve
Telerik team
Brian
Top achievements
Rank 1
Share this question
or