locked
bind the rdlc report from code behind RRS feed

  • Question

  • User-1474096950 posted
    i binded the rdlc using the physical dataset created using wizard in webapplication now i have a SP which is executed in dataset how do i bind the rdlc report from code behind cmd.CommandType = CommandType.StoredProcedure; SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds= new DataSet(); da.Fill(ds); ReportViewer1.LocalReport.ReportPath = Server.MapPath("reports/PR.rdlc"); ReportDataSource rdS = new ReportDataSource("X_PR_DataTable1", GetData()); ReportViewer1.LocalReport.DataSources.Clear(); ReportViewer1.LocalReport.DataSources.Add(rdS); but how ca i bind from above & add fields to the reprort
    Saturday, June 9, 2012 3:28 AM

Answers

  • User-8475372 posted

    -Create and RDLC file

    - Create a connection to the RDLC file with SQL server using DATASOURCE

    - Create Dataset which will bring up the query results which you have to show up in your report.

    - Bind that Dataset to the tablix or matrix report depending on the requiremnt. 

    - Use Preview to view the report results.

    - To embed this report in your .net application .. use the below mentioned code. 

    This code helps in connecting with the reports hosted in the MS-SSRS through .NET code. (Example is with C# 4.0 Framework)
    ----------------------------------------------------------------------------------------------------------------
    Microsoft.Reporting.WebForms.ReportParameter[] RptParameters;


                reportViewer.ServerReport.ReportServerUrl = new System.Uri(ConfigurationManager.AppSettings["ReportServerURL"]);
                reportViewer.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
                reportViewer.ToolBarItemBorderColor = System.Drawing.Color.PowderBlue;
                reportViewer.ToolBarItemBorderStyle = BorderStyle.Double;


                string strUserName = ConfigurationManager.AppSettings["UserName"].ToString();
                string strPassword = ConfigurationManager.AppSettings["Password"].ToString();
                string strDomain = ConfigurationManager.AppSettings["Domain"].ToString();
                reportViewer.ServerReport.ReportServerCredentials = new ReportCredentials(strUserName, strPassword, strDomain);
                string strReport = string.Empty;
                strReport = ConfigurationManager.AppSettings["ReportsFolder"] + Request.QueryString["ReportName"].ToString();


    Below snippet shows on how to pass parameters to the report  :


                    this.reportViewer.ServerReport.ReportPath = strReport;
                    RptParameters = new Microsoft.Reporting.WebForms.ReportParameter[1];
                    RptParameters[0] = new Microsoft.Reporting.WebForms.ReportParameter("                                                      <ParameterName>", "<ParameterValue>");               
                    this.reportViewer.ServerReport.SetParameters(RptParameters);     
                    reportViewer.ServerReport.Refresh();


    You can pass any number of parameters to the report. Just make sure that the <ParameterName> matches with the parameter name in the report. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 18, 2012 8:25 AM

All replies

  • User-37275327 posted

    Create the report schema first using exisitng SP. Add a new typed DataSet and configure it with the SP and save. Then dataset will be appear on the report designer. There you can drag & drop fields to the report.

    Monday, June 11, 2012 2:14 AM
  • User-8475372 posted

    -Create and RDLC file

    - Create a connection to the RDLC file with SQL server using DATASOURCE

    - Create Dataset which will bring up the query results which you have to show up in your report.

    - Bind that Dataset to the tablix or matrix report depending on the requiremnt. 

    - Use Preview to view the report results.

    - To embed this report in your .net application .. use the below mentioned code. 

    This code helps in connecting with the reports hosted in the MS-SSRS through .NET code. (Example is with C# 4.0 Framework)
    ----------------------------------------------------------------------------------------------------------------
    Microsoft.Reporting.WebForms.ReportParameter[] RptParameters;


                reportViewer.ServerReport.ReportServerUrl = new System.Uri(ConfigurationManager.AppSettings["ReportServerURL"]);
                reportViewer.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
                reportViewer.ToolBarItemBorderColor = System.Drawing.Color.PowderBlue;
                reportViewer.ToolBarItemBorderStyle = BorderStyle.Double;


                string strUserName = ConfigurationManager.AppSettings["UserName"].ToString();
                string strPassword = ConfigurationManager.AppSettings["Password"].ToString();
                string strDomain = ConfigurationManager.AppSettings["Domain"].ToString();
                reportViewer.ServerReport.ReportServerCredentials = new ReportCredentials(strUserName, strPassword, strDomain);
                string strReport = string.Empty;
                strReport = ConfigurationManager.AppSettings["ReportsFolder"] + Request.QueryString["ReportName"].ToString();


    Below snippet shows on how to pass parameters to the report  :


                    this.reportViewer.ServerReport.ReportPath = strReport;
                    RptParameters = new Microsoft.Reporting.WebForms.ReportParameter[1];
                    RptParameters[0] = new Microsoft.Reporting.WebForms.ReportParameter("                                                      <ParameterName>", "<ParameterValue>");               
                    this.reportViewer.ServerReport.SetParameters(RptParameters);     
                    reportViewer.ServerReport.Refresh();


    You can pass any number of parameters to the report. Just make sure that the <ParameterName> matches with the parameter name in the report. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 18, 2012 8:25 AM