子报表的数据检索失败,';子报表4';,只发生在1台电脑上,但没有发生在其他电脑上
本文关键字:电脑 报表 其他 数据 检索 失败 1台 | 更新日期: 2023-09-27 18:28:35
我有一个VS2013(用C#x32编写)桌面应用程序正在访问托管的SQL Server 2012。它有一个包含4个子报表的报表。在我将其安装到几台电脑上后,其中一台电脑出现了上述问题,但其他电脑正确显示了报告。奇怪的是问题PC在子报表4的中途显示了这个错误。所有电脑都在Windows 7(x32/64)上运行。我真的不知道如何找出为什么它只发生在一台基本上与其他电脑相似的电脑上
报告的编码如下:-
public partial class ReportProject : Form
{
cl_Class1 mySettings = new cl_Class1();
SqlConnection conReport = new SqlConnection();
public ReportProject()
{
InitializeComponent();
this.Text = "Test Report";
// Add a handler for SubreportProcessing
reportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessing);
}
// data set at the class level to access by all methods
DataSet dsReport = new dsTestReport();
private void ReportProject_Load(object sender, EventArgs e)
{
// connection to database
conReport.ConnectionString = mySettings.myConnString;
SqlCommand cmdReport = new SqlCommand();
SqlDataReader drReport;
try
{
// open connection
conReport.Open();
cmdReport.CommandType = CommandType.Text;
cmdReport.Connection = conReport;
// get query string from builder
string strMain = "aaaaa";
string strSub1 = "bbbbb";
string strSub2 = "ccccc";
string strSub3 = "ddddd";
cmdReport.CommandText = strMain + strSub1 + strSub2 + strSub3;
// execute query and load result to dataset
drReport = cmdReport.ExecuteReader();
dsReport.Load(drReport, LoadOption.OverwriteChanges, dsReport.Tables[0], dsReport.Tables[1], dsReport.Tables[2], dsReport.Tables[3]);
// close connection
drReport.Close();
conReport.Close();
// prepare report for view
reportViewer1.LocalReport.ReportEmbeddedResource = "myProgram.rptMain.rdlc";
ReportDataSource rds = new ReportDataSource();
rds.Name = "DataSet1";
rds.Value = dsReport.Tables[0];
reportViewer1.LocalReport.DataSources.Add(rds);
// preview the report
reportViewer1.RefreshReport();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (conReport.State == ConnectionState.Open)
{
conReport.Close();
}
}
}
void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
string myReportName = e.ReportPath;
if (myReportName == "rptSubReport1")
{
e.DataSources.Add(new ReportDataSource("DataSet1", dsReport.Tables[1]));
}
if (myReportName == "rptSubReport2")
{
e.DataSources.Add(new ReportDataSource("DataSet1", dsReport.Tables[2]));
}
if (myReportName == "rptSubReport3")
{
e.DataSources.Add(new ReportDataSource("DataSet1", dsReport.Tables[3]));
}
if (myReportName == "rptSubReport4")
{
e.DataSources.Add(new ReportDataSource("DataSet1", dsReport.Tables[3]));
}
}
}
注:SubReport3和SubReport4使用相同的数据集(dsReport.Tables[3])
将建议/帮助解决此问题。提前谢谢!
最后,我从这台电脑上卸载了reportviewer运行时(这是唯一一台拥有reportviewer副本的电脑)。卸载后,报告现在可以正常运行!尽管这似乎解决了问题,但我仍然很困惑为什么会出现这种情况——也许reportviewer运行时中存在与编译的软件冲突的内容。