Assigning report to reportviewer programatically

2 posts, 0 answers
  1. clinton
    clinton avatar
    1 posts
    Member since:
    Aug 2018

    Posted 12 Aug Link to this post

    Hi,

    I am very new to Telerik.  I am trying to add a report that I created, into a reportviewer programatically and I was able to successfully do it with a static "Hello World" report.  Now my problem is I am trying the same but this time with a report requiring several parameters and the report is not displaying in the viewer.

    Here is my code below.  I have also attached the output on my browser.  I would appreciate it if anyone can point out whatever I am missing, with some examples.  I am sure it something very silly that I completely missed out.  Thanks.

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Telerik.ReportViewer.Html5.WebForms.ReportSource rptSource = new Telerik.ReportViewer.Html5.WebForms.ReportSource();
            rptSource.IdentifierType = Telerik.ReportViewer.Html5.WebForms.IdentifierType.TypeReportSource;
            rptSource.Identifier = typeof(SellThroughSummary).AssemblyQualifiedName;
            rptSource.Parameters.Add("CoName","Beside LLC");
            rptSource.Parameters.Add("BrandDes", "ALL");
            rptSource.Parameters.Add("SeasonDes", "SS18");
            rptSource.Parameters.Add("StoreDes", "TDM-D");
            rptSource.Parameters.Add("GenDes", "ALL");
            rptSource.Parameters.Add("CatDes", "ALL");
            rptSource.Parameters.Add("Descr", "ALL");
            rptSource.Parameters.Add("FromDt", "2018-01-01");
            rptSource.Parameters.Add("ToDt", "2018-01-31");
     
            this.ReportViewer1.ReportSource = rptSource;
     
            Telerik.Reporting.SqlDataSource sqlDataSource = new Telerik.Reporting.SqlDataSource();
            sqlDataSource.ProviderName = "System.Data.SqlClient";
            sqlDataSource.ConnectionString = "ReportLibrary.Properties.Settings.ReportServer";
            sqlDataSource.SelectCommand = "MIS_SellThru";
            sqlDataSource.SelectCommandType = Telerik.Reporting.SqlDataSourceCommandType.StoredProcedure;
            sqlDataSource.Parameters.Add("CoName", System.Data.DbType.String, "Beside LLC");
            sqlDataSource.Parameters.Add("BrandDes", System.Data.DbType.String, "ALL");
            sqlDataSource.Parameters.Add("SeasonDes", System.Data.DbType.String, "SS18");
            sqlDataSource.Parameters.Add("StoreDes", System.Data.DbType.String, "TDM-D");
            sqlDataSource.Parameters.Add("GenDes", System.Data.DbType.String, "ALL");
            sqlDataSource.Parameters.Add("CatDes", System.Data.DbType.String, "ALL");
            sqlDataSource.Parameters.Add("Descr", System.Data.DbType.String, "ALL");
            sqlDataSource.Parameters.Add("FromDt", System.Data.DbType.String, "2018-01-01");
            sqlDataSource.Parameters.Add("ToDt", System.Data.DbType.String, "2018-01-31");
            sqlDataSource.CommandTimeout = 0;
        }       
    }

     

     

  2. Silviya
    Admin
    Silviya avatar
    185 posts

    Posted 15 Aug Link to this post

    Hello Clinton,

    I will post my answer from the support ticket you have opened on the same topic:

    "When the SQL query has parameters you can set their value on step 4 of SqlDataSource Wizard. On this step, you can map the value of data source parameter to a report parameter - Using Parameters with Data Source objects. This way you can use the standard report parameter user interface to provide values for your data source parameters.

    So, to bind the SQL Query Parameters to Report Parameters in your case, you will need to do the following:
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Telerik.ReportViewer.Html5.WebForms.ReportSource rptSource = new Telerik.ReportViewer.Html5.WebForms.ReportSource();
            rptSource.IdentifierType = Telerik.ReportViewer.Html5.WebForms.IdentifierType.TypeReportSource;
            rptSource.Identifier = typeof(SellThroughSummary).AssemblyQualifiedName;
            rptSource.Parameters.Add("CoName","Beside LLC");
            rptSource.Parameters.Add("BrandDes", "ALL");
            rptSource.Parameters.Add("SeasonDes", "SS18");
            rptSource.Parameters.Add("StoreDes", "TDM-D");
            rptSource.Parameters.Add("GenDes", "ALL");
            rptSource.Parameters.Add("CatDes", "ALL");
            rptSource.Parameters.Add("Descr", "ALL");
            rptSource.Parameters.Add("FromDt", "2018-01-01");
            rptSource.Parameters.Add("ToDt", "2018-01-31");
      
            this.ReportViewer1.ReportSource = rptSource;
      
            Telerik.Reporting.SqlDataSource sqlDataSource = new Telerik.Reporting.SqlDataSource();
            sqlDataSource.ProviderName = "System.Data.SqlClient";
            sqlDataSource.ConnectionString = "ReportLibrary.Properties.Settings.ReportServer";
            sqlDataSource.SelectCommand = "MIS_SellThru";
            sqlDataSource.SelectCommandType = Telerik.Reporting.SqlDataSourceCommandType.StoredProcedure;
            sqlDataSource.Parameters.Add("CoName", System.Data.DbType.String, "=Parameters.CoName");
            sqlDataSource.Parameters.Add("BrandDes", System.Data.DbType.String, "=Parameters.BrandDes");
            sqlDataSource.Parameters.Add("SeasonDes", System.Data.DbType.String, "=Parameters.SeasonDes");
            sqlDataSource.Parameters.Add("StoreDes", System.Data.DbType.String, "=Parameters.StoreDes");
            sqlDataSource.Parameters.Add("GenDes", System.Data.DbType.String, "=Parameters.GenDes");
            sqlDataSource.Parameters.Add("CatDes", System.Data.DbType.String, "=Parameters.CatDes");
            sqlDataSource.Parameters.Add("Descr", System.Data.DbType.String, "=Parameters.Descr");
            sqlDataSource.Parameters.Add("FromDt", System.Data.DbType.String, "=Parameters.FromDt");
            sqlDataSource.Parameters.Add("ToDt", System.Data.DbType.String, "=Parameters.ToDt");
            sqlDataSource.CommandTimeout = 0;
     
    report.DataSource = sqlDataSource; //you will also need to bind the data source to the report
        }      
    }

    This could be achieved directly in the report definition. For example, you could use the 
    SqlDataSource Wizard which includes a step by step guide to set the values of data source parameters and connection string at design-time - step 4 (Configure Data Source Parameters).

    Please note that these report parameters must be created in the report definition before applying values to them from the client report source.

    Additional note: The syntax used for the placeholders varies, depending on the type of the database. If you are working with SQL Server, the parameter name begins with the '@' character, and its name corresponds to the name of the parameter object in the Parameters collection. So, in your case you can rename data source parameters names like for example: @CoName, @BrandDes etc."


    Regards,
    Silviya
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top