我有一个带有组合框和日期时间选择器的表单。我希望用户从组合框中选择一个值并选择一个日期,该值需要作为参数捕获并显示在报告中,其中日期等于所选日期,itempiececode 等于所选组合框值。
涉及的部分
表格 - Piece Code.cs 报告 - Report6.rdlc 表格上的 ReportViewer 片段 Code.cs - 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,所以没有太多代码可以共享
我需要的总结 我需要将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;
}
}
}
}
我收到以下错误“值不在预期范围内”。在这部分代码reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("reportfiller_DataTable1", fullpiecedetails));