【发布时间】: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