priya pawar

priya pawar

  • NA
  • 2
  • 4.1k

Data retrieval failed for the subreport, Please check the lo

Jan 28 2014 8:16 AM
please anybody can help me who have faced the same above problem while calling RDLC Subreport in winform.
I have 2 tables 1) BankAccount & 2)BankAccountDetail.
The relation between the two is by using bankCode field.
Now I want to display a report to show records from BankAccount table followed by the detail records from BankAccountDetail table as subreport.
 
My main report is getting populated but below is what I have coded into winforms it raises an error stating Data retrieval failed for the subreport
private void button1_Click(object sender, EventArgs e)
{
sqlAdapt.Fill(ds, "BankAccount");
sqlConn.Close();
sqlConn.Dispose();
this.reportViewer1.Reset();
this.reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
this.reportViewer1.LocalReport.ReportPath = @"D:\vs 2012\RDLC\IBF\IBF\repBank.rdlc";
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DSBankAccount",ds.Tables["BankAccount"]));
this.reportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessing);
reportViewer1.DocumentMapCollapsed = true;
reportViewer1.RefreshReport();
}
void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
string str = "";
str = "Data Source=UTO2005-LAB;Initial Catalog=RFA_MVC;Persist Security Info=True;User ID=sa;Password=welcome#321";
SqlConnection sqlConn = new SqlConnection(str);
try
{
switch (e.ReportPath) // name of subreport
{
case "subRptBankDetail":
string query = "select * From BankAccountDetails";
sqlConn.Open();
SqlCommand sqlCmd = new SqlCommand(query, sqlConn);
sqlCmd.CommandText = query + " where BankCode = " + (e.Parameters["BankCode"].Values.First()).ToString();
SqlDataAdapter sqlAdapt = new SqlDataAdapter(sqlCmd);
DataSet ds = new DataSet();
sqlAdapt.Fill(ds, "BankAccountDetails");
e.DataSources.Add(new ReportDataSource("DSBankDetail", ds.Tables["BankAccountDetails"]));
break;
}
}
catch (Exception ex)
{
ex.Message.ToString();
}
}
}