如何在报表上显示组合框值
本文关键字:组合 显示 报表 | 更新日期: 2023-09-27 18:34:42
我有一个带有组合框和日期时间选择器的表单。 我希望用户从组合框中选择一个值并选择一个日期,并且需要将此值捕获为参数并显示在报表上,其中日期等于所选日期,itempiececode 等于所选组合框值。
涉及的部分
表格 - 计件代码.cs报告 - 报告6.rdlc表单代码上的报表查看器.cs - 报表查看器1
如果您仍然不明白我的问题是什么,请单击 ->图片
突出显示的黄色是我需要的。
到目前为止我拥有的代码
填充报表查看器
private void PieceCode_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'CorsicanaNetWeightDataSet9.CandyPieceSize' table. You can move, or remove it, as needed.
this.CandyPieceSizeTableAdapter.Fill(this.CorsicanaNetWeightDataSet9.CandyPieceSize);
// TODO: This line of code loads data into the 'CorsicanaNetWeightDataSet4.PieceDimensionMasterDataUpdate' table. You can move, or remove it, as needed.
this.PieceDimensionMasterDataUpdateTableAdapter.Fill(this.CorsicanaNetWeightDataSet4.PieceDimensionMasterDataUpdate);
// TODO: This line of code loads data into the 'corsicanaNetWeightDataSet4piece.Item_Piece' table. You can move, or remove it, as needed.
this.item_PieceTableAdapter.Fill(this.corsicanaNetWeightDataSet4piece.Item_Piece);
PieceReport pr = new PieceReport();
reportViewer1.Visible = false;
this.reportViewer1.RefreshReport();
}
为了填充组合框,我使用了数据源和显示memeber属性** 我使用报告向导生成报告6**
我在大部分程序中都使用了GUI,因此没有太多代码可以共享
我需要的摘要我需要将 Combobox1.selectedtext 设置为等于 Report6 上的一个参数,并将 DateTimepicker.text = 设置为另一个参数,以便我可以在我的报表查看器中显示它?或者该程序是否有任何其他解决方法。
我在这里完全诚实,请不要将其作为题外话关闭,或者让我失望,因为我已经提供了我所拥有的一切供您理解,请帮助我,因为这是我项目的最后一部分,我真的很想在假期前完成它并与家人共度时光,感谢您的所有帮助
用代码尝试过,GUI 有时不会削减它
namespace CorsicanaNetWeightProgram
{
public partial class PieceCode : Form
{
public string constr = "Data Source=KCMJF1XTR1''SQLEXPRESS;Initial Catalog=CorsicanaNetWeight;Integrated Security=True";
public reportfiller fullpiecedetails;
public piecedescription piece;
PieceReport pr = new PieceReport();
public PieceCode()
{
InitializeComponent();
}
private void PieceCode_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'CorsicanaNetWeightDataSet9.CandyPieceSize' table. You can move, or remove it, as needed.
// TODO: This line of code loads data into the 'corsicanaNetWeightDataSet4piece.Item_Piece' table. You can move, or remove it, as needed.
// this.item_PieceTableAdapter.Fill(this.corsicanaNetWeightDataSet4piece.Item_Piece);
PieceReport pr = new PieceReport();
reportViewer1.Visible = false;
piece = new piecedescription();
fillpiece();
this.reportViewer1.RefreshReport();
}
private void fillpiece()
{
try
{
using(MSSQL.SqlConnection connection = new MSSQL.SqlConnection(constr))
{
connection.Open ();
using (MSSQL.SqlCommand command = new MSSQL.SqlCommand("SELECT Item + '-' + Description AS PieceDescription FROM dbo.[Piece Dimension Master Data]" ,connection))
{
MSSQL.SqlDataAdapter myadapter = new System.Data.SqlClient.SqlDataAdapter();
myadapter.SelectCommand = command;
myadapter.Fill(piece, "DataTable1");
comboBox1.DataSource = piece.DataTable1;
comboBox1.ValueMember = "PieceDescription";
comboBox1.DisplayMember = "PieceDescription";
}
}
}
catch (Exception) { /*Handle error*/ }
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
reportViewer1.Visible = true;
{
using (MSSQL.SqlConnection connection = new MSSQL.SqlConnection(constr))
{
fullpiecedetails = new reportfiller();
connection.Open();
//MSSQL.SqlCommand command = new MSSQL.SqlCommand("SELECT * From EtimePunchDetail WHERE (EmpID = @empid) And (Paygroup = @paygroup) And (TransDate >= @fromdate) And (TransDate <= @todate)", connection);
MSSQL.SqlCommand command = new MSSQL.SqlCommand("SELECT * FROM dbo.[Piece Dimension Master Data] WHERE Item + '-' + Description = @piecedesc", connection);
{
MSSQL.SqlParameter parmEmp = new MSSQL.SqlParameter();
parmEmp.ParameterName = "@piecedesc";
parmEmp.Value = comboBox1.SelectedValue;
command.Parameters.Add(parmEmp);
MSSQL.SqlDataAdapter EtimePunchDetailTableAdapter = new System.Data.SqlClient.SqlDataAdapter();
EtimePunchDetailTableAdapter.SelectCommand = command;
EtimePunchDetailTableAdapter.Fill(fullpiecedetails, "DataTable1");
string exeFolder = Path.GetDirectoryName(Application.ExecutablePath);
string reportPath = exeFolder + @"'Report6.rdlc";
reportViewer1.LocalReport.ReportPath = reportPath;
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("reportfiller_DataTable1", fullpiecedetails));
reportViewer1.RefreshReport();
reportViewer1.Refresh();
reportViewer1.Visible = true;
}
}
}
}
我收到以下错误"值不在预期范围内"。在代码的这一部分 reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("reportfiller_DataTable1", fullpiecedetails((;
假设日期的参数名称是日期参数。要设置该值,我将执行以下操作:
ReportParameter rpDateParameter = new ReportParameter();
rpDateParameter.Name = "DateParameter";
rpDateParameter.Values.Add(dateTimePicker1.Value.ToString());
reportViewer1.LocalReport.SetParameters(new ReportParameter[] { rpDateParameter });
// Refresh the report
reportViewer1.RefreshReport();
我创建了一个新表单,添加了新报告,新数据集并通过GUI完成了所有操作 - 使用向导生成报告。
我将数据集编辑为以下代码
SELECT Item, Description, [Piece Category], Shape, [Deposit Weight], [Center Weight], [Center Weight Constant], [Coating Weight], [Coating Weight Constant], [Decorations Weight], [Inclusions Weight], [Center Diameter_LL], [Center Diameter_UL], [Center Length_LL], [Center Length_UL], [Center Width_LL], [Center Width_UL], [Center Height_LL], [Center Height_UL], [Center Weight Variation], [Coated Diameter_LL], [Coated Diameter_UL], [Coated Length_LL], [Coated Length_UL], [Coated Width_LL], [Coated Width_UL], [Coated Height_LL], [Coated Height_UL], [Coated Weight Variation], Item + '-' + Description AS [PieceDescription] FROM [Piece Dimension Master Data] WHERE **Item + '-' + Description = @piece**
然后向报表中添加了一个包含所有必填列的表
。GUI 为我生成了此代码
namespace CorsicanaNetWeightProgram
{
public partial class PieceCodepc : Form
{
public PieceCodepc()
{
InitializeComponent();
}
private void PieceCodepc_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'dataSet1.DataTable1' table. You can move, or remove it, as needed.
this.dataTable1TableAdapter.Fill(this.dataSet1.DataTable1);
}
private void button1_Click(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'empty.Piece_Dimension_Master_Data' table. You can move, or remove it, as needed.
this.Piece_Dimension_Master_DataTableAdapter.Fill(this.empty.Piece_Dimension_Master_Data, comboBox1.SelectedValue.ToString());
this.reportViewer1.RefreshReport();
}
}
}
我所做的只是将comboBox1.SelectedValue.ToString((传递给DataTableAdapter,它起作用了