我遵循了本教程https://www.aspsnippets.com/Articles/Adding-Charts-to-ASPNet-ReportViewer-Control-Display-Pie-Chart-in-RDLC-Report-in-ASPNet.aspx和本教程https://www.codeproject.com/articles/15597/using-the-asp-net-2-0-reportviewer-in-local-mode
毋庸置疑,两者都很有效。
问题是,在与我的wapplication交互五分钟后,当我回到包含我得到的报告的网络表单时:
无可用数据
基于这些教程的两个报告都会发生这种情况 就像我的数据集在5分钟后被拔掉一样 到目前为止我找到的解决方案是重新整理整个报告,让它再工作5到10分钟。我不知道这是怎么发生的。以下是我正在使用的代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/report1.rdlc");
DataSetArticle Myds = GetData();
ReportDataSource datasource = new ReportDataSource("dsReport", Myds .Tables[0]);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(datasource);
}
}
protected DataSetArticle GetData()
{
string query = "select cola, colb from mytable";
string conString = "myconnection string";
SqlCommand cmd = new SqlCommand(query);
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSetArticle dsMe = new DataSet1())
{
sda.Fill(dsMe, "DataTable1");
return dsMe;
}
}
}
}
}
的图片
调试器的图像