You must Sign In to post a response.
  • Category: Windows

    Report viewer with multiple rdlc files

    Hi,

    How can i add different rdlc files to one report viewer in windows application.

    i tried it then it gives error as
    "Report definition for 'rptReport' hasnot been specified"
  • #747232
    String RequestType=null;
    Public FrmPurchaseRequestType(string ReqType)//constructor
    {
    InitializeComponent();
    this.RequestType=ReqType;
    Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1=new Microsoft.Reporting.WinForms.ReportDataSource();
    reportDataSource1.Name="DataSet_PurchaseRequestTypes";
    reportDataSource1Value=this.Purchase_Request_TypesBindingSource;
    this.reportViewer1.LocalReport.DataSource.Add(reportDataSource1);
    If(RequestType =="Raw Material Report")
    {
    this.reportViewer1.LocalReport.ReportEmbeddedResource ="Report1.rdlc";
    }
    else
    {
    Add here another report
    }
    this.Purchase_Request_TypesTableAdapter.Fill(DataSet.Purchase_Request_Types,RequestType);
    this.reportViewer1.RefreshRepot();
    }

  • #747589
    you can try this function to pass all parameter.



    public static void frmReport_GetData(
    ReportViewer rptViewer,
    DataSet dsName,
    string strsqlquery,
    string strReportEmbeddedResource,
    string strDisplayName,
    string strrdsName)
    {
    rptViewer.Clear();
    dsName.Clear();
    //declare Connection, command and other related objects
    SqlConnection conReport = new SqlConnection(objconnect);
    SqlCommand cmdReport = new SqlCommand();
    SqlDataReader drReport;
    try
    {
    //open connection
    conReport.Open();
    //prepare connection object to get the data through reader and populate into dataset
    cmdReport.CommandType = CommandType.Text;
    cmdReport.Connection = conReport;
    rptViewer.Clear();
    /* Sql Query */
    cmdReport.CommandText = strsqlquery;
    //read data from command object
    drReport = cmdReport.ExecuteReader();
    //new cool thing with ADO.NET… load data directly from reader to dataset
    dsName.Tables[0].Load(drReport);
    //close reader and connection
    drReport.Close();
    conReport.Close();
    //provide local report information to viewer
    rptViewer.LocalReport.ReportEmbeddedResource = strReportEmbeddedResource;
    rptViewer.LocalReport.DisplayName = strDisplayName;
    //prepare report data source
    ReportDataSource rds = new ReportDataSource();
    rds.Name = strrdsName;
    rds.Value = dsName.Tables[0];
    rptViewer.LocalReport.DataSources.Add(rds);
    //load report viewer
    rptViewer.RefreshReport();
    }
    catch (Exception ex)
    {
    //display generic error message back to user
    MessageBox.Show(ex.Message);
    }
    finally
    {
    //check if connection is still open then attempt to close it
    if (conReport.State == ConnectionState.Open)
    {
    conReport.Close();
    }
    }
    rptViewer.RefreshReport();
    }


  • Sign In to post your comments