INSTRUCTIONS FOR SETTING A REPORT PARAMETER IN VS2005:
FOR RDLC:
1. SET
FOR FORM WITH REPORT VIEWER CONTROL:
2. PLACE A PANEL AND DROP-DOWN CONTROL
ON FORM
3. WRITE METHOD TO POPULATE COMBOBOX:
2. ADD A METHOD: SetReportParameters();
TO FORM_LOAD EVENT BEFORE THE reportViewer1.RefreshReport(); LINE
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using Microsoft.Reporting.WinForms;
namespace USM2
{
public partial class frmRptSurvey1
: Form
{
public frmRptSurvey1()
{
InitializeComponent();
}
private void
frmRptSurvey1_Load(object sender, EventArgs e)
{
//populate combo box for parameter selection:
populateComboBox();
}
private void
fillReportData()
{
if (EIDDropDown.SelectedIndex > -1)
{
usm_variables.iEstimateID = Convert.ToInt32(EIDDropDown.Text);
}
this.estimate_procedureTableAdapter.FillByEstimateID(this.usmDataSet_survey1.estimate_procedure,
usm_variables.iEstimateID);
this.angle_ironsTableAdapter.FillByEstimateID(this.usmDataSet_survey1.angle_irons,
usm_variables.iEstimateID);
this.pipeTableAdapter.FillByEstimateID(this.usmDataSet_survey1.pipe, usm_variables.iEstimateID);
this.barsTableAdapter.FillByEstimateID(this.usmDataSet_survey1.bars, usm_variables.iEstimateID);
this.railTableAdapter.FillByEstimateID(this.usmDataSet_survey1.rail, usm_variables.iEstimateID);
this.givenTableAdapter.FillByEstimateID(this.usmDataSet_survey1.given, usm_variables.iEstimateID);
this.cylinderTableAdapter.FillByEstimateID(this.usmDataSet_survey1.cylinder, usm_variables.iEstimateID);
this.beams_channelsTableAdapter.FillByEstimateID(this.usmDataSet_survey1.beams_channels,
usm_variables.iEstimateID);
this.cabinetTableAdapter.FillByEstimateID(this.usmDataSet_survey1.cabinet, usm_variables.iEstimateID);
this.estimatesTableAdapter.FillByEstimateID(this.usmDataSet_survey1.estimates, usm_variables.iEstimateID);
this.company_infoTableAdapter.FillByEstimateID(this.usmDataSet_survey1.company_info,
usm_variables.iEstimateID);
}
private void
populateComboBox()
{
OleDbConnection cnn = new OleDbConnection(usm_variables.strCnn);
OleDbDataReader dr = null;
try
{
EIDDropDown.Items.Clear();
string sSQL = "SELECT DISTINCT ESTIMATE_ID FROM estimate_procedure WHERE
active <> 0 ORDER BY ESTIMATE_ID";
cnn.Open();
OleDbCommand cmd = new OleDbCommand(sSQL, cnn);
dr = cmd.ExecuteReader();
if (dr != null)
{
while (dr.Read())
{
EIDDropDown.Items.Add(dr["ESTIMATE_ID"]);
}
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (dr != null)
{
dr.Close();
}
cnn.Close();
}
}
private void
SetReportParameters()
{
ReportParameter[] parameters = new
ReportParameter[1];
parameters[0] = new ReportParameter("EstimateID", EIDDropDown.Text);
this.reportViewer1.LocalReport.SetParameters(parameters);
}
private void
EIDDropDown_SelectedIndexChanged(object sender, EventArgs e)
{
if (EIDDropDown.SelectedIndex > -1)
{
//set parameters
SetReportParameters();
//fill report with data
fillReportData();
this.reportViewer1.RefreshReport();
}
}
}
}