C# 如何在报表上显示我的组合框值?

C# 如何在报表上显示我的组合框值?,c#,winforms,parameters,combobox,reportviewer2008,C#,Winforms,Parameters,Combobox,Reportviewer2008,我有一个带有组合框和日期时间选择器的表单。我希望用户从组合框中选择一个值并选择一个日期,该值需要作为参数捕获并显示在报告上,其中日期等于所选日期,itempiececode等于所选组合框值 涉及的部分 表单-piecode.cs 报告-Report6.rdlc 表单Piece Code.cs上的ReportViewer-reportviewer1 如果您仍然不明白我的问题是什么,请单击-> 突出显示的黄色是我需要的 我的代码已经很长了 以填充reportviewer private void P

我有一个带有组合框和日期时间选择器的表单。我希望用户从组合框中选择一个值并选择一个日期,该值需要作为参数捕获并显示在报告上,其中日期等于所选日期,itempiececode等于所选组合框值

涉及的部分

表单-piecode.cs 报告-Report6.rdlc 表单Piece Code.cs上的ReportViewer-reportviewer1

如果您仍然不明白我的问题是什么,请单击->

突出显示的黄色是我需要的

我的代码已经很长了

以填充reportviewer

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();
}
为了填充组合框,我使用了datasource和displaymemeber属性 **我使用报表向导生成报表6**

我在大部分程序中都使用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.selectedtext设置为等于report6上的一个参数,并将datetimepicker.text=设置为另一个参数,以便在reportviewer中显示它??或者该计划是否有其他解决方法

我在这里是完全诚实的,请不要将此作为离题的话题来结束,或将我拒之门外,因为我已经提供了所有我所拥有的东西供您理解,请帮助我,因为这是我项目的最后一部分,我真的很想在假期前完成它,并花时间与家人在一起谢谢您的帮助

使用代码进行了尝试,但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;
                   }
                }
            }

        }
名称空间科西嘉网络程序
{
公共部分类代码:表单
{
public string constr=“Data Source=KCMJF1XTR1\\SQLEXPRESS;Initial Catalog=corsicananeweight;Integrated Security=True”;
公开报告详情;
公共物品描述物品;
PieceReport pr=新的PieceReport();
公共代码()
{
初始化组件();
}
私有无效片段代码加载(对象发送方,事件参数e)
{
//TODO:这行代码将数据加载到“CorsicanaNetWeightDataSet9.CandypeceSize”表中。您可以根据需要移动或删除它。
//TODO:这行代码将数据加载到“CorsicanaNetweightDataset4Parte.Item\u Piece”表中。您可以根据需要移动或删除它。
//此.item\u Piece表格适配器.Fill(此.CorsicanaNetweightDataset4件.item\u Piece);
PieceReport pr=新的PieceReport();
reportViewer1.Visible=false;
工件=新工件描述();
圆角();
this.reportViewer1.RefreshReport();
}
专用空白填充件()
{
尝试
{
使用(MSSQL.SqlConnection连接=新的MSSQL.SqlConnection(constr))
{
connection.Open();
使用(MSSQL.SqlCommand命令=新的MSSQL.SqlCommand(“从dbo中选择项+'-'+描述作为工件描述。[工件尺寸主数据]”,连接))
{
MSSQL.SqlDataAdapter myadapter=new System.Data.SqlClient.SqlDataAdapter();
myadapter.SelectCommand=command;
myadapter.Fill(件号“数据表1”);
comboBox1.DataSource=piece.DataTable1;
comboBox1.ValueMember=“PieceDescription”;
comboBox1.DisplayMember=“PieceDescription”;
}
}
}
捕获(异常){/*句柄错误*/}
}
私有无效dateTimePicker1\u值已更改(对象发送方,事件参数e)
{          
}
私有无效按钮1\u单击(对象发送者,事件参数e)
{ 
reportViewer1.Visible=true;
{
使用(MSSQL.SqlConnection连接=新的MSSQL.SqlConnection(constr))
{
fullpiecedetails=新的reportfiller();
connection.Open();

//MSSQL.SqlCommand command=new MSSQL.SqlCommand(“从EtimePunchDetail中选择*,其中(EmpID=@EmpID)和(Paygroup=@Paygroup)和(TransDate>=@fromdate)和(TransDate表示日期的参数名为DateParameter。要设置该值,我将执行以下操作:

        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,它成功了!!!!

我尝试了一些类似于您的代码的方法,但我得到的结果是“值不在预期的错误范围内”。我在问题中添加了我的代码,请查看以供参考。