【问题标题】:C# ReportViewer The source of the Report Definition has not been specifiedC# ReportViewer 未指定报表定义的来源
【发布时间】:2021-11-08 07:38:00
【问题描述】:

请帮我解决这个问题

我有一个与 SQL 服务器连接的 C# 项目 我想预览这个项目中的报告,但不知道为什么我的代码不起作用

//ReportDataSource reportDataSource;
try
{
    // Set the processing mode for the ReportViewer to Remote  
    reportViewer1.ProcessingMode = ProcessingMode.Remote;

    ServerReport serverReport = reportViewer1.ServerReport;

    // Get a reference to the default credentials  
    System.Net.ICredentials credentials =
        System.Net.CredentialCache.DefaultCredentials;

    // Get a reference to the report server credentials  
    ReportServerCredentials rsCredentials =
        serverReport.ReportServerCredentials;

    // Set the credentials for the server report  
    rsCredentials.NetworkCredentials = credentials;

    //this.reportViewer1.LocalReport.ReportPath = Application.StartupPath + @"\Reports\Report1.rdlc";
    this.reportViewer1.LocalReport.DataSources.Clear();

    DataSet1 dataSet1 = new DataSet1();
    SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
    
    con.Open();
    sqlDataAdapter.SelectCommand = new SqlCommand(@"SELECT 
                                                    dbo.Sales.product_name, dbo.Sales.price_dollar, dbo.Sales.price_dinar, dbo.Sales.quantity, dbo.Sales.totoal_dollar, dbo.Sales.total_dinar
                                                    FROM   dbo.Customers INNER JOIN
                                                    dbo.SaleReport ON dbo.Customers.customer_id = dbo.SaleReport.customer_id INNER JOIN
                                                    dbo.Sales ON dbo.SaleReport.trans_no = dbo.Sales.trans_no
                                                    where Sales.trans_no = '" + 1 + "';", con);
    sqlDataAdapter.Fill(dataSet1.Tables["Products"]);
    con.Close();

    ReportDataSource dsSalesOrder = new ReportDataSource();
    dsSalesOrder.Name = "DataSet1";
    dsSalesOrder.Value = dataSet1.Tables["Products"];

    //reportDataSource = new ReportDataSource("DataSet1", dataSet1.Tables["Products"]);

    reportViewer1.LocalReport.DataSources.Clear();
    reportViewer1.LocalReport.DataSources.Add(dsSalesOrder);
    reportViewer1.LocalReport.ReportEmbeddedResource = @"Report2.rdlc";
    reportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
    reportViewer1.ZoomMode = ZoomMode.Percent;
    reportViewer1.ZoomPercent = 100;
    reportViewer1.LocalReport.Refresh();
    reportViewer1.RefreshReport();
}
catch (Exception ex)
{
    con.Close();
    MessageBox.Show(ex.Message);
    throw;
}

【问题讨论】:

  • 如果您继续这样做,多次重复问题中的相同文本将被标记为垃圾邮件。

标签: c# sql-server winforms rdlc reportviewer


【解决方案1】:

就像错误所说的那样,

报告定义的来源尚未指定

您需要先指定rdlc模板文件,然后才能添加参数或生成报告。

我认为你只是调用了错误的方法, 行:

reportViewer1.LocalReport.ReportEmbeddedResource = @"Report2.rdlc";

实际上应该是:

reportViewer1.LocalReport.ReportPath = @"Report2.rdlc";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-11
    • 1970-01-01
    • 2021-09-14
    • 1970-01-01
    • 2013-09-29
    • 1970-01-01
    相关资源
    最近更新 更多