setting report parameters and displaying a .rdlc report ona report viewer

  • Thread starter Thread starter WindyD
  • Start date Start date
W

WindyD

Guest
Im developing a windows form application. there Im using a report iewer to view and print reports. The form which contains the report viewer has a text box where user need to specify the BHT No. (primary key of the two tables named "patient", "BMarrow") and whan the user entersthe BHT No. and click a button named "viwe report " I want to display the data relevant to that BHT no. in the report1.rdlc of report viewer.

I wroe the following statements while assigning parameters for the fields of datasets of the .rdlc report

private void button1_Click(object sender, EventArgs e)
{
SqlConnection myconnection1 = new SqlConnection("user=sa;" + "password=123;" + "server=USER-PC\\SQLEXPRESS;" + "Trusted_Connection=Yes;" + "database=Hematology;" + "Connection timeout=30;");
myconnection1.Open();
SqlCommand report = new SqlCommand("Select * FROM Patient p, BMarrow b WHERE p.BHT=b.BHT AND p.BHT= " + textBox1.Text + ";", myconnection1);
SqlDataReader reader2 = report.ExecuteReader();
if (reader2 != null)
{
if (reader2.Read())
{

//this form has reportviewer 1 and report1.rdlc is the report viewd in that report viewer
/*I have created 3 datasets under report data and dataset1 stands for the Patient table and datase2
stands for the BMarrow table from those two daasets I have dragged and dropped the attributes
into the text boxes in report1.rdlc*/
ReportParameterCollection reportParameters2 = new ReportParameterCollection();
reportParameters2.Add(new ReportParameter("Name", reader2.GetValue(0).ToString()));
reportParameters2.Add(new ReportParameter("Age", reader2.GetValue(1).ToString()));
reportParameters2.Add(new ReportParameter("Sex", reader2.GetValue(2).ToString()));
reportParameters2.Add(new ReportParameter("Ward", reader2.GetValue(3).ToString()));
reportParameters2.Add(new ReportParameter("BHT", reader2.GetValue(4).ToString()));
reportParameters2.Add(new ReportParameter("Indication", reader2.GetValue(5).ToString()));
reportParameters2.Add(new ReportParameter("BM", reader2.GetValue(6).ToString()));
reportParameters2.Add(new ReportParameter("Difficulty", reader2.GetValue(7).ToString()));
reportParameters2.Add(new ReportParameter("SiteOfAspiration", reader2.GetValue(8).ToString()));
reportParameters2.Add(new ReportParameter("Cellularity", reader2.GetValue(9).ToString()));
reportParameters2.Add(new ReportParameter("Erythropoiesis", reader2.GetValue(10).ToString()));
reportParameters2.Add(new ReportParameter("Granulopoiesis", reader2.GetValue(11).ToString()));
reportParameters2.Add(new ReportParameter("Megakaryocytes", reader2.GetValue(12).ToString()));
reportParameters2.Add(new ReportParameter("Abnormal", reader2.GetValue(13).ToString()));
reportParameters2.Add(new ReportParameter("SpecialStains", reader2.GetValue(14).ToString()));
reportParameters2.Add(new ReportParameter("Lymphocytes", reader2.GetValue(15).ToString()));
reportParameters2.Add(new ReportParameter("Conclusion", reader2.GetValue(16).ToString()));
reportParameters2.Add(new ReportParameter("Date", reader2.GetValue(17).ToString()));

this.reportViewer1.LocalReport.SetParameters(reportParameters2);



}

}

there were no building errors

but when I run the application and when the form containing the report viewer is opened the report viewer shows "The Name parameter is missing a value" and after giving the BHT No. to the text box and when the view button (button1) is clicked, it show an error saying

Microsoft.Reporting.WinForms.LocalProcessingException was unhandled
Message=An error occurred during local report processing.
Source=Microsoft.ReportViewer.WinForms
what is this :(((((

What is the error in this code. I have no idea regarding this.

please help if you know something regarding this exception

Continue reading...
 
Back
Top