我想要完成的是有一个漂亮的报告供用户打印。所以我现在使用SQL Server来获取我的数据我想将它放在我的报表查看器中。我担心它看起来很糟糕,让整件事浪费时间。理想的情况是使报表看起来像您可以使用报表应用程序创建但基于Web的报表。例如,在他们的Intranet系统上,他们打开Web浏览器,然后转到报告。我怎么能做到这一点?如果您有更好的解决方案或知道如何制作基于网络的更好的报告,我愿意接受建议。
以下是我目前对此解决方案的尝试:
SqlCommand sqlString = new SqlCommand("SELECT WorkOrderNumber, LNumber FROM WorkOrder ");
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
sqlString.CommandType = CommandType.Text;
sqlString.Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ToString());
da.SelectCommand = sqlString;
da.Fill(ds, "DataSet1");
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", ds.Tables[0]));
ReportViewer1.LocalReport.Refresh();
答案 0 :(得分:0)
public static class ReportParameters
{
private static ReportParameter[] _parameters= null;
public static ReportParameter[] Parameters
{
get { return _parameters; }
set { _parameters = value; }
}
private static String _ReportName = String.Empty;
public static String ReportName
{
get { return _ReportName; }
set { _ReportName = value; }
}
}
protected void SendToRenderReport()
{
ReportParameter[] parameters = new ReportParameter[3];
parameters[0] = new ReportParameter("StartDate", txtStartDate.Text);
parameters[1] = new ReportParameter("EndDate", txtEndDate.Text);
parameters[2] = new ReportParameter("DealerID", ddlDealer.SelectedValue);
//Set Report Parameters which you assigned above
ReportParameters.Parameters = parameters;
//Set Report Name and redirect to report page
ReportParameters.ReportName = "/ReportFolder/ReportName";
Response.Redirect("Reports.aspx");
}
以下是report.aspx页面上的代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
if (ReportParameters.Parameters != null && ReportParameters.ReportName != "")
RenderReport(ReportParameters.Parameters, ReportParameters.ReportName);
}
public void RenderReport(ReportParameter[] prams, String reportName)
{
var reportServerUrl = "report server path, set and read from config";
rptView.ServerReport.ReportServerUrl = new System.Uri(reportServerUrl);
rptView.ServerReport.ReportPath = reportName;
rptView.ProcessingMode = ProcessingMode.Remote;
var rsUserName = "set and read from config";
string rsPassword = "set and read from config";
string rsDomain = "set and read from config";
rptView.ServerReport.ReportServerCredentials =
new CustomReportCredentials(rsUserName, rsPassword, rsDomain);
rptView.ServerReport.SetParameters(prams);
rptView.ShowCredentialPrompts = false;
rptView.ServerReport.Refresh();
}
rptView是report.aspx页面上的报告查看器